From 3abd4f36d023a586c09a686febcbeb1cc7718623 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Mon, 4 Feb 2013 20:14:33 -0500 Subject: [PATCH] setting up grapelli autocomplete for Note >> Course relation, closes #60 --- karmaworld/apps/courses/models.py | 4 ++++ karmaworld/apps/notes/admin.py | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 6bc2f03..40deedc 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -97,6 +97,10 @@ class Course(models.Model): self.slug = defaultfilters.slugify("%s %s" % (self.name, self.id)) super(Course, self).save(*args, **kwargs) # Save the slug + @staticmethod + def autocomplete_search_fields(): + return ("name__icontains",) + def update_note_count(self): """ Update self.file_count by summing the note_set """ self.file_count = self.note_set.count() diff --git a/karmaworld/apps/notes/admin.py b/karmaworld/apps/notes/admin.py index 650e9cb..91eab81 100644 --- a/karmaworld/apps/notes/admin.py +++ b/karmaworld/apps/notes/admin.py @@ -5,8 +5,16 @@ from django.contrib import admin -from karmaworld.apps.notes import models +from karmaworld.apps.notes.models import DriveAuth +from karmaworld.apps.notes.models import Note +class NoteAdmin(admin.ModelAdmin): + """ an Admin handler for the Note model that handles autocomplete to Course + """ + raw_id_fields = ('course',) + autocomplete_lookup_fields = { + 'fk': ['course'] + } -admin.site.register(models.DriveAuth) -admin.site.register(models.Note) +admin.site.register(DriveAuth) +admin.site.register(Note, NoteAdmin) -- 2.25.1