You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from django.shortcuts import render, get_object_or_404
|
|
import wishlist.models as m
|
|
import django.views.generic as dv
|
|
|
|
class WishedItemView(dv.DetailView):
|
|
model = m.WishedItem
|
|
template_name = 'wishlist/item.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
ctx = super().get_context_data(**kwargs)
|
|
ctx['page_title'] = f"Item: {ctx['object']}"
|
|
return ctx
|
|
|
|
class UserWishLists(dv.ListView):
|
|
model = m.WishList
|
|
template_name = 'wishlist/userwishlists.html'
|
|
|
|
def get_queryset(self):
|
|
qs = super().get_queryset()
|
|
return qs.filter(owner__login=self.loginname)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
ctx = super().get_context_data(**kwargs)
|
|
ctx['page_title'] = f"{ctx['object']}'s wishlists"
|
|
return ctx
|
|
|
|
class WishListView(dv.ListView):
|
|
model = m.WishedItem
|
|
template_name = 'wishlist/wishlist.html'
|
|
|
|
def get_queryset(self):
|
|
qs = super().get_queryset()
|
|
return qs.filter(wishlists__slug__in=[self.kwargs["slug"]])
|
|
|
|
def get_context_data(self, **kwargs):
|
|
ctx = super().get_context_data(**kwargs)
|
|
ctx['wishlist'] = get_object_or_404(m.WishList, slug=self.kwargs['slug'])
|
|
ctx['page_title'] = f"Wishlist: {ctx['wishlist']}"
|
|
return ctx
|