2024-05-25 20:34:59 +00:00
|
|
|
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2024-05-17 18:46:38 +00:00
|
|
|
from django.contrib import admin
|
2024-07-06 17:26:21 +00:00
|
|
|
from django.db import transaction
|
2024-05-21 09:21:13 +00:00
|
|
|
from note_kfet.admin import admin_site
|
2024-05-17 18:46:38 +00:00
|
|
|
|
2024-07-03 17:20:01 +00:00
|
|
|
from .models import Allergen, BasicFood, QRCode, TransformedFood
|
2024-05-21 09:21:13 +00:00
|
|
|
|
|
|
|
|
2024-07-03 17:20:01 +00:00
|
|
|
@admin.register(QRCode, site=admin_site)
|
|
|
|
class QRCodeAdmin(admin.ModelAdmin):
|
2024-07-06 17:26:21 +00:00
|
|
|
pass
|
2024-05-21 09:21:13 +00:00
|
|
|
|
2024-07-03 17:20:01 +00:00
|
|
|
|
|
|
|
@admin.register(BasicFood, site=admin_site)
|
|
|
|
class BasicFoodAdmin(admin.ModelAdmin):
|
2024-07-06 17:26:21 +00:00
|
|
|
@transaction.atomic
|
|
|
|
def save_related(self, *args, **kwargs):
|
|
|
|
ans = super().save_related(*args, **kwargs)
|
|
|
|
args[1].instance.update()
|
|
|
|
return ans
|
2024-05-21 09:21:13 +00:00
|
|
|
|
2024-07-03 17:20:01 +00:00
|
|
|
|
|
|
|
@admin.register(TransformedFood, site=admin_site)
|
|
|
|
class TransformedFoodAdmin(admin.ModelAdmin):
|
2024-07-06 17:26:21 +00:00
|
|
|
exclude = ["allergens", "expiry_date"]
|
|
|
|
|
|
|
|
@transaction.atomic
|
2024-07-08 15:44:09 +00:00
|
|
|
def save_related(self, request, form, *args, **kwargs):
|
|
|
|
super().save_related(request, form, *args, **kwargs)
|
|
|
|
form.instance.update()
|
2024-05-21 09:21:13 +00:00
|
|
|
|
2024-07-03 17:20:01 +00:00
|
|
|
|
|
|
|
@admin.register(Allergen, site=admin_site)
|
2024-05-21 09:21:13 +00:00
|
|
|
class AllergenAdmin(admin.ModelAdmin):
|
2024-07-06 17:26:21 +00:00
|
|
|
pass
|