View for "my images"

This commit is contained in:
reverend 2022-12-25 13:49:44 +01:00
parent 1df19b8a74
commit a54ad8954c
3 changed files with 20 additions and 3 deletions

View File

@ -24,6 +24,11 @@
Upload image Upload image
</a> </a>
</li> </li>
<li class="RV-Navigation__item">
<a href="{% url 'my_images' %}" class="RV-Navigation__link">
My images
</a>
</li>
<li class="RV-Navigation__item"> <li class="RV-Navigation__item">
<a href="#" class="RV-Navigation__link"> <a href="#" class="RV-Navigation__link">
My galleries My galleries

View File

@ -2,10 +2,12 @@ from django.urls import path
from .views import ( from .views import (
ImageUploadView, ImageUploadView,
PublicImageListView PublicImageListView,
MyImagesListView
) )
urlpatterns = [ urlpatterns = [
path('', PublicImageListView.as_view(), name='home'), path('', PublicImageListView.as_view(), name='home'),
path('upload/', ImageUploadView.as_view(), name='upload_image') path('upload/', ImageUploadView.as_view(), name='upload_image'),
path('my_images/', MyImagesListView.as_view(), name='my_images')
] ]

View File

@ -15,7 +15,7 @@ class VisitorSessionMixin(View):
def get_visitor(self): def get_visitor(self):
if self.request.session: if self.request.session:
if 'visitor_session' in self.request.session: if 'visitor_session' in self.request.session:
if Visitor.objects.get(session_id=self.request.session['visitor_session']).exists(): if Visitor.objects.filter(session_id=self.request.session['visitor_session']).exists():
return Visitor.objects.get(session_id=self.request.session['visitor_session']) return Visitor.objects.get(session_id=self.request.session['visitor_session'])
else: else:
visitor = Visitor.objects.create() visitor = Visitor.objects.create()
@ -72,3 +72,13 @@ class PublicImageListView(ListView):
def get_queryset(self): def get_queryset(self):
return Image.objects.all().filter(private=False) return Image.objects.all().filter(private=False)
class MyImagesListView(VisitorSessionMixin, ListView):
model = Image
paginated_by = 20
context_object_name = 'images'
template_name = 'list_images/image_list.html'
def get_queryset(self):
return Image.objects.all().filter(uploaded_by=self.get_visitor())