mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
dal ingredient endpoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
|
|
||||||
from cookbook.models import Keyword
|
from cookbook.models import Keyword, RecipeIngredients
|
||||||
|
|
||||||
|
|
||||||
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
|
class KeywordAutocomplete(autocomplete.Select2QuerySetView):
|
||||||
@@ -14,3 +14,16 @@ class KeywordAutocomplete(autocomplete.Select2QuerySetView):
|
|||||||
qs = qs.filter(name__istartswith=self.q)
|
qs = qs.filter(name__istartswith=self.q)
|
||||||
|
|
||||||
return qs
|
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
|
||||||
|
|||||||
@@ -50,4 +50,5 @@ urlpatterns = [
|
|||||||
path('api/sync_all/', api.sync_all, name='api_sync'),
|
path('api/sync_all/', api.sync_all, name='api_sync'),
|
||||||
|
|
||||||
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
|
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
|
||||||
|
path('dal/ingredient/', dal.IngredientsAutocomplete.as_view(), name='dal_ingredient'),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user