mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-11-01 16:14:30 +01:00
Autocomplete food on ManageIngredients now show owners
This commit is contained in:
@@ -21,9 +21,13 @@ class FoodSerializer(serializers.ModelSerializer):
|
||||
REST API Serializer for Food.
|
||||
The djangorestframework plugin will analyse the model `Food` and parse all fields in the API.
|
||||
"""
|
||||
# This fields is used for autocompleting food in ManageIngredientsView
|
||||
# TODO Find a better way to do it
|
||||
owner_name = serializers.CharField(source='owner.name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Food
|
||||
fields = '__all__'
|
||||
fields = ['name', 'owner', 'allergens', 'expiry_date', 'end_of_life', 'is_ready', 'order', 'owner_name']
|
||||
|
||||
|
||||
class BasicFoodSerializer(serializers.ModelSerializer):
|
||||
|
||||
@@ -167,7 +167,7 @@ class ManageIngredientsForm(forms.Form):
|
||||
model=Food,
|
||||
resetable=True,
|
||||
attrs={"api_url": "/api/food/food",
|
||||
"class": "autocomplete"},
|
||||
"class": "autocomplete manageingredients-autocomplete"},
|
||||
)
|
||||
name.label = _('Name')
|
||||
|
||||
|
||||
@@ -413,13 +413,12 @@ class TestFoodAPI(TestAPI):
|
||||
"""
|
||||
self.check_viewset(BasicFoodViewSet, '/api/food/basicfood/')
|
||||
|
||||
# TODO Repair and detabulate this test
|
||||
def test_transformedfood_api(self):
|
||||
"""
|
||||
Load TransformedFood API page and test all filters and permissions
|
||||
"""
|
||||
# TODO Repair this test
|
||||
pass
|
||||
# self.check_viewset(TransformedFoodViewSet, '/api/food/transformedfood/')
|
||||
self.check_viewset(TransformedFoodViewSet, '/api/food/transformedfood/')
|
||||
|
||||
def test_qrcode_api(self):
|
||||
"""
|
||||
|
||||
@@ -769,7 +769,7 @@ class OrderListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, L
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
activity = Activity.objects.get(pk=self.kwargs["activity_pk"])
|
||||
return Order.objects.filter(activity=activity)
|
||||
return Order.objects.filter(activity=activity).order_by('number')
|
||||
|
||||
def get_tables(self):
|
||||
activity = Activity.objects.get(pk=self.kwargs["activity_pk"])
|
||||
|
||||
@@ -13,11 +13,14 @@ $(document).ready(function () {
|
||||
target.addClass('is-invalid')
|
||||
target.removeClass('is-valid')
|
||||
|
||||
const isManageIngredients = target.hasClass('manageingredients-autocomplete')
|
||||
|
||||
$.getJSON(api_url + (api_url.includes('?') ? '&' : '?') + 'format=json&search=^' + input + api_url_suffix, function (objects) {
|
||||
let html = '<ul class="list-group list-group-flush" id="' + prefix + '_list">'
|
||||
|
||||
objects.results.forEach(function (obj) {
|
||||
html += li(prefix + '_' + obj.id, obj[name_field])
|
||||
const extra = isManageIngredients ? ` (${obj.owner_name})` : ''
|
||||
html += li(`${prefix}_${obj.id}`, `${obj[name_field]}${extra}`)
|
||||
})
|
||||
html += '</ul>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user