From 1fee4cf1b3bc294450736485e9592937f377a028 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sat, 16 Apr 2011 19:02:02 +0000 Subject: [PATCH] default-ordering tweaks. Mostly for making Django Admin more useable. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1373 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/admin.py | 27 +++++++++++++++++++++++++-- conifer/syrup/models.py | 20 +++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/conifer/syrup/admin.py b/conifer/syrup/admin.py index ebf34c9..693d32a 100644 --- a/conifer/syrup/admin.py +++ b/conifer/syrup/admin.py @@ -1,13 +1,36 @@ from django.contrib import admin import django.db.models +from django import forms from conifer.syrup.models import * -for m in [ServiceDesk, Group, Membership, Course, +for m in [ServiceDesk, Group, Course, Department, Site, Term, - UserProfile, Config, Z3950Target]: +Config, Z3950Target]: admin.site.register(m) class ItemAdmin(admin.ModelAdmin): model = Item admin.site.register(Item, ItemAdmin) + +class MembershipAdminForm(forms.ModelForm): + user = forms.ModelChoiceField(queryset=User.objects.order_by('username')) + + class Meta: + model = Membership + +class MembershipAdmin(admin.ModelAdmin): + form = MembershipAdminForm + +admin.site.register(Membership, MembershipAdmin) + +class UserProfileAdminForm(forms.ModelForm): + user = forms.ModelChoiceField(queryset=User.objects.order_by('username')) + + class Meta: + model = UserProfile + +class UserProfileAdmin(admin.ModelAdmin): + form = UserProfileAdminForm + +admin.site.register(UserProfile, UserProfileAdmin) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 403e00a..f07a737 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -40,8 +40,12 @@ class BaseModel(m.Model): # the User object (although UserProfile would be another logical # candidate). + class UserExtensionMixin(object): + class Meta: + ordering = ['username'] + def sites(self, role=None): self.maybe_refresh_external_memberships() sites = Site.objects.filter(group__membership__user=self.id).distinct() @@ -146,6 +150,9 @@ class UserProfile(BaseModel): def __unicode__(self): return 'UserProfile(%s)' % self.user + class Meta: + ordering = ['user__username'] + #---------------------------------------------------------------------- # Lookup tables @@ -158,6 +165,9 @@ class ServiceDesk(BaseModel): def __unicode__(self): return self.name + class Meta: + ordering = ['name'] + @classmethod def default(cls): return cls.objects.get(pk=Config.get('default.desk', 1)) @@ -210,6 +220,9 @@ class Department(BaseModel): def __unicode__(self): return self.name + class Meta: + ordering = ['name'] + class Course(BaseModel): """An abstract course (not a course offering.)""" @@ -288,7 +301,7 @@ class Site(BaseModel): class Meta: unique_together = (('course', 'start_term', 'owner')) - ordering = ['-start_term__start', 'course__code', 'owner__last_name'] + ordering = ['course__code', 'owner__last_name', '-start_term__start'] def save(self, *args, **kwargs): # Assert that the term-order is logical. @@ -519,11 +532,16 @@ class Group(BaseModel): def __unicode__(self): return u"Group('%s', '%s')" % (self.site, self.external_id or '(internal)') + class Meta: + ordering = ['site__course__code', 'site__course__name', 'external_id'] + class Membership(BaseModel): class Meta: unique_together = (('group', 'user')) + ordering = ['user__username', + 'group__site__course__code', 'group__site__course__name', 'group__external_id'] user = m.ForeignKey(User) group = m.ForeignKey(Group) -- 2.11.0