Commits

Patrick Guido Arminio  committed 5cf5b9a

Ordinamento dei piatti e dei menu nell'admin.

  • Participants
  • Parent commits cdf363b

Comments (0)

Files changed (1)

File projectmensa/menu/admin.py

 from django.contrib import admin
+from django.forms import ModelForm, ModelMultipleChoiceField
 
 from models import *
 
 from pdf_utils import pdf_to_courses
 
 
+class CourseAdmin(admin.ModelAdmin):
+    ordering = ['name']
+
+
+class ProductAdminForm(ModelForm):
+    courses = ModelMultipleChoiceField(queryset=Course.objects.order_by('name'))
+
+    class Meta:
+        model = MenuOfTheDay
+
+
 class MenuAdmin(admin.ModelAdmin):
+    ordering = ['-day']
+    form = ProductAdminForm
+
     def save_model(self, request, obj, form, change):
         """
         L'admin di Django ha un bug con il salvataggio dei m2m
 
             form.cleaned_data['courses'].append(c)
 
-admin.site.register(Course)
+admin.site.register(Course, CourseAdmin)
 admin.site.register(TypeToken)
 admin.site.register(MenuOfTheDay, MenuAdmin)