Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

some admin hacking

  • Loading branch information...
commit 1323e970b066cee799a25e5b1785a223367b27bf 1 parent c1ca4fb
@f4nt authored
Showing with 48 additions and 1 deletion.
  1. +33 −1 anitracker/admin.py
  2. +15 −0 anitracker/models.py
View
34 anitracker/admin.py
@@ -2,6 +2,38 @@
from anitracker import models
+
+class AdmissionAdmin(admin.ModelAdmin):
+ fieldsets = (
+ (None, {
+ 'fields': ('date_of_admission', 'received_from')
+ }),
+ ('Animal Information', {
+ 'fields': ('animal', 'animal_age', 'disposition',
+ 'disposition_date', 'released_to')
+ }),
+ ('Misc.', {
+ 'fields': ('follow_up', 'notes')
+ }),
+ )
+ list_filter = (
+ 'date_of_admission',
+ 'disposition',
+ 'follow_up',
+ 'animal_age',
+ 'animal__name'
+ )
+ list_display = ('date_of_admission', 'animal', 'disposition', 'follow_up')
+
+ def formfield_for_foreignkey(self, db_field, request, **kwargs):
+ if db_field.name == 'released_to':
+ kwargs['queryset'] = models.Person.objects.receivers
+
+ if db_field.name == 'received_from':
+ kwargs['queryset'] = models.Person.objects.finders
+
+ return super(AdmissionAdmin, self).formfield_for_foreignkey(
+ db_field, request, **kwargs)
admin.site.register(models.Animal)
admin.site.register(models.Person)
-admin.site.register(models.Admission)
+admin.site.register(models.Admission, AdmissionAdmin)
View
15 anitracker/models.py
@@ -22,6 +22,19 @@ class Animal(BaseModel):
def __unicode__(self):
return '%s - %s' % (self.name, self.sub_type)
+class PersonManager(models.Manager):
+ ''' Manager for Person Class '''
+
+ @property
+ def finders(self):
+ return self.filter(
+ person_type=self.model.FINDER)
+
+ @property
+ def receivers(self):
+ return self.filter(
+ person_type=self.model.RECEIVER)
+
class Person(BaseModel):
''' Person that dropped off, or received animal '''
@@ -46,6 +59,8 @@ class Person(BaseModel):
person_type = models.CharField(
max_length=16, choices=PERSON_TYPES)
+ objects = PersonManager()
+
def __unicode__(self):
return u'%s %s - %s' % (self.first_name, self.last_name, self.zipcode)
Please sign in to comment.
Something went wrong with that request. Please try again.