From 166079553589f642fc03594ea67720267c9c3b24 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Tue, 29 Jan 2013 16:47:39 -0500 Subject: [PATCH] adding django-grapelli, and adding a fkey lookup from Course to School model --- karmaworld/apps/courses/admin.py | 14 +++++++++++--- karmaworld/apps/courses/models.py | 4 ++++ karmaworld/settings/common.py | 3 +++ karmaworld/urls.py | 2 ++ reqs/common.txt | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/karmaworld/apps/courses/admin.py b/karmaworld/apps/courses/admin.py index e484058..6984901 100644 --- a/karmaworld/apps/courses/admin.py +++ b/karmaworld/apps/courses/admin.py @@ -5,7 +5,15 @@ from django.contrib import admin -import models +from karmaworld.apps.courses.models import School +from karmaworld.apps.courses.models import Course -admin.site.register(models.School) -admin.site.register(models.Course) +class CourseAdmin(admin.ModelAdmin): + """ an Admin handler for the Course model that handles fk search """ + raw_id_fields = ('school',) + autocomplete_lookup_fields = { + 'fk': ['school'] + } + +admin.site.register(School) +admin.site.register(Course, CourseAdmin) diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 000394a..604bba7 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -37,6 +37,10 @@ class School(models.Model): self.slug = defaultfilters.slugify(self.name) super(School, self).save(*args, **kwargs) + @staticmethod + def autocomplete_search_fields(): + return ("name__icontains",) + def update_note_count(self): """ Update the School.file_count by summing the contained course.file_count diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index 5b5d021..e3ac330 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -187,6 +187,9 @@ DJANGO_APPS = ( # Useful template tags: 'django.contrib.humanize', + # grappelli django-admin improvment, must be added before admin + 'grappelli', + # Admin panel and documentation: 'django.contrib.admin', 'django.contrib.admindocs', diff --git a/karmaworld/urls.py b/karmaworld/urls.py index 9f96a56..49a2861 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -23,6 +23,8 @@ urlpatterns = patterns('', # Admin panel and documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), + # Grappelli django-admin improvment suite + url(r'^grappelli/', include('grappelli.urls')), url(r'^terms/$', direct_to_template, { 'template': 'terms.html' }, name='terms'), diff --git a/reqs/common.txt b/reqs/common.txt index d92f368..60643ef 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -8,3 +8,4 @@ git+git://github.com/FinalsClub/django-taggit.git oauth2client==1.0 urllib3==1.5 google-api-python-client==1.0 +django-grappelli==2.4.3 -- 2.25.1