diff --git a/django_lostplaces/lostplaces/models/models.py b/django_lostplaces/lostplaces/models/models.py index 2d39ca6..5914583 100644 --- a/django_lostplaces/lostplaces/models/models.py +++ b/django_lostplaces/lostplaces/models/models.py @@ -62,6 +62,12 @@ class Explorer(models.Model): verbose_name='Explorers favorite places', blank=True ) + visited_places = models.ManyToManyField( + Place, + related_name='explorer_visits', + verbose_name='Explorers visited places', + blank=True + ) def __str__(self): return self.user.username diff --git a/django_lostplaces/lostplaces/templates/explorer/profile.html b/django_lostplaces/lostplaces/templates/explorer/profile.html index 8bdd07d..f8779b6 100644 --- a/django_lostplaces/lostplaces/templates/explorer/profile.html +++ b/django_lostplaces/lostplaces/templates/explorer/profile.html @@ -92,9 +92,21 @@ {% endfor %} - {% include 'partials/nav/pagination.html' %} + + +
+
+

{% trans 'Visited places' %}

+ + {% include 'partials/nav/pagination.html' %}
diff --git a/django_lostplaces/lostplaces/templates/partials/icons/place_visited.html b/django_lostplaces/lostplaces/templates/partials/icons/place_visited.html new file mode 100644 index 0000000..79232c2 --- /dev/null +++ b/django_lostplaces/lostplaces/templates/partials/icons/place_visited.html @@ -0,0 +1,14 @@ +{%load static %} +{% load i18n %} + +{% if request.user %} +{% if place in request.user.explorer.visited_places.all %} + + + +{%else%} + + + +{% endif %} +{% endif %} \ No newline at end of file diff --git a/django_lostplaces/lostplaces/templates/partials/place_teaser.html b/django_lostplaces/lostplaces/templates/partials/place_teaser.html index aa1418f..7028eb1 100644 --- a/django_lostplaces/lostplaces/templates/partials/place_teaser.html +++ b/django_lostplaces/lostplaces/templates/partials/place_teaser.html @@ -31,7 +31,7 @@
diff --git a/django_lostplaces/lostplaces/templates/place/place_detail.html b/django_lostplaces/lostplaces/templates/place/place_detail.html index 5db1360..dbbd06f 100644 --- a/django_lostplaces/lostplaces/templates/place/place_detail.html +++ b/django_lostplaces/lostplaces/templates/place/place_detail.html @@ -23,7 +23,7 @@
-

{{ place.name }} {% include 'partials/icons/place_favorite.html' %}

+

{{ place.name }} {% include 'partials/icons/place_favorite.html' %} {% include 'partials/icons/place_visited.html' %}

{% if place.placeimages.first.filename.hero.url %}
diff --git a/django_lostplaces/lostplaces/urls.py b/django_lostplaces/lostplaces/urls.py index a7560ec..35f6ce4 100644 --- a/django_lostplaces/lostplaces/urls.py +++ b/django_lostplaces/lostplaces/urls.py @@ -15,6 +15,8 @@ from lostplaces.views import ( PlaceTagSubmitView, PlaceFavoriteView, PlaceUnfavoriteView, + PlaceVisitCreateView, + PlaceVisitDeleteView, PlaceImageCreateView, PlaceImageDeleteView, PhotoAlbumCreateView, @@ -36,14 +38,16 @@ urlpatterns = [ path('place/create/', PlaceCreateView.as_view(), name='place_create'), path('place/update//', PlaceUpdateView.as_view(), name='place_edit'), path('place/delete//', PlaceDeleteView.as_view(), name='place_delete'), - path('place/tag/create/', PlaceTagSubmitView.as_view(), name='place_tag_submit'), - path('place/tag/delete//', PlaceTagDeleteView.as_view(), name='place_tag_delete'), + path('place/tag/create//', PlaceTagSubmitView.as_view(), name='place_tag_submit'), + path('place/tag/delete///', PlaceTagDeleteView.as_view(), name='place_tag_delete'), path('place/fav/create//', PlaceFavoriteView.as_view(), name='place_favorite'), path('place/fav/delete//', PlaceUnfavoriteView.as_view(), name='place_unfavorite'), + path('place/visit/create//', PlaceVisitCreateView.as_view(), name='place_visit_create'), + path('place/visit/delete//', PlaceVisitDeleteView.as_view(), name='place_visit_delete'), - path('place_image/create/', PlaceImageCreateView.as_view(), name='place_image_create'), - path('place_image/delete/', PlaceImageDeleteView.as_view(), name='place_image_delete'), + path('place_image/create//', PlaceImageCreateView.as_view(), name='place_image_create'), + path('place_image/delete//', PlaceImageDeleteView.as_view(), name='place_image_delete'), - path('photo_album/create/', PhotoAlbumCreateView.as_view(), name='photo_album_create'), - path('photo_album/delete/', PhotoAlbumDeleteView.as_view(), name='photo_album_delete') + path('photo_album/create//', PhotoAlbumCreateView.as_view(), name='photo_album_create'), + path('photo_album/delete//', PhotoAlbumDeleteView.as_view(), name='photo_album_delete') ] diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index 379f02e..29069db 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -147,3 +147,23 @@ class PlaceUnfavoriteView(IsAuthenticatedMixin, View): request.user.explorer.save() return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk})) + +class PlaceVisitCreateView(IsAuthenticatedMixin, View): + + def get(self, request, place_id): + place = get_object_or_404(Place, id=place_id) + if request.user is not None: + request.user.explorer.visited_places.add(place) + request.user.explorer.save() + + return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk})) + +class PlaceVisitDeleteView(IsAuthenticatedMixin, View): + + def get(self, request, place_id): + place = get_object_or_404(Place, id=place_id) + if request.user is not None: + request.user.explorer.visited_places.remove(place) + request.user.explorer.save() + + return redirect_referer_or(request, reverse('place_detail', kwargs={'pk': place.pk}))