Use autocomplete for list of wishlists (WIP)
Note to self: forgetting to add dal to INSTALLED_APPS leads to names in it not being available, although dal itself exists.newer-dal
parent
2b12c8fc9e
commit
a50fb8ce24
@ -1,8 +1,10 @@
|
||||
from django.urls import path
|
||||
from . import views as v
|
||||
from . import views_autocomplete as ac
|
||||
|
||||
urlpatterns = [
|
||||
path('user/<str:loginname>', v.UserWishLists.as_view(), name='wishlists_user'),
|
||||
path('item/<int:pk>', v.WishedItemView.as_view(), name='wished_item'),
|
||||
path('<slug:slug>', v.WishListView.as_view(), name='wishlist'),
|
||||
path('autocomplete/wishlists', ac.WishListAutocomplete.as_view(), name='wishlist_list_autocomplete'),
|
||||
]
|
||||
|
@ -0,0 +1,14 @@
|
||||
from dal import autocomplete
|
||||
from wishlist.models import WishList
|
||||
|
||||
class WishListAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if not self.request.user.is_authenticated:
|
||||
return WishList.objects.none()
|
||||
qs = WishList.objects.all().filter(owner=self.request.user)
|
||||
|
||||
if self.q:
|
||||
qs = qs.filter(name__startswith=self.q)
|
||||
|
||||
return qs
|
||||
|
Loading…
Reference in New Issue