adding django-grapelli, and adding a fkey lookup from Course to School model
authorSeth Woodworth <seth@sethish.com>
Tue, 29 Jan 2013 21:47:39 +0000 (16:47 -0500)
committerSeth Woodworth <seth@sethish.com>
Tue, 29 Jan 2013 21:47:39 +0000 (16:47 -0500)
karmaworld/apps/courses/admin.py
karmaworld/apps/courses/models.py
karmaworld/settings/common.py
karmaworld/urls.py
reqs/common.txt

index e484058cbc92b9d9ca999ece48c131a92e399dee..6984901bf6870e6b279fec6b0f335995881694ef 100644 (file)
@@ -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)
index 000394ae2b3e5d47fec86e9c8e7e9f11d156d163..604bba7fb0e93120cec133f05a5cadad08be145b 100644 (file)
@@ -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
index 5b5d0212e96fc2602ffaff200935d5b5772733db..e3ac330deff4e6ddc23bf7bf65fcbd34c588ce38 100644 (file)
@@ -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',
index 9f96a5611534132c5d74a7bd8d70503572f97026..49a2861cef06a019020f2f0e983dd27928ab18c3 100644 (file)
@@ -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'),
 
index d92f3680d0f65a3f2f72135032c0dd87fa873905..60643efd6a7c8a053b9d6026492ec3bb4cb8ee3e 100644 (file)
@@ -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