dal ingredient endpoint

This commit is contained in:
vabene1111 2019-11-19 21:16:31 +01:00
parent 78157cb359
commit 53ee5b8124
2 changed files with 15 additions and 1 deletions

View File

@ -1,6 +1,6 @@
from dal import autocomplete
from cookbook.models import Keyword
from cookbook.models import Keyword, RecipeIngredients
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
@ -14,3 +14,16 @@ class KeywordAutocomplete(autocomplete.Select2QuerySetView):
qs = qs.filter(name__istartswith=self.q)
return qs
class IngredientsAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
if not self.request.user.is_authenticated:
return RecipeIngredients.objects.none()
qs = RecipeIngredients.objects.all()
if self.q:
qs = qs.filter(name__istartswith=self.q)
return qs

View File

@ -50,4 +50,5 @@ urlpatterns = [
path('api/sync_all/', api.sync_all, name='api_sync'),
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
path('dal/ingredient/', dal.IngredientsAutocomplete.as_view(), name='dal_ingredient'),
]