Permalink
Browse files

Grappelli-enabled demo

  • Loading branch information...
mpasternak committed Aug 24, 2012
1 parent 7698ddc commit b5f55445816ef542c1513fc179a2a1a5c0cc9dfe
@@ -0,0 +1,20 @@
+from django.contrib import admin
+
+import autocomplete_light
+
+from models import Foo, Bar
+
+
+class FooInline(admin.TabularInline):
+ model = Foo
+
+
+class FooAdmin(admin.ModelAdmin):
+ form = autocomplete_light.modelform_factory(Foo)
+admin.site.register(Foo, FooAdmin)
+
+
+class BarAdmin(admin.ModelAdmin):
+ form = autocomplete_light.modelform_factory(Bar)
+ inlines = [FooInline]
+admin.site.register(Bar, BarAdmin)
@@ -0,0 +1,6 @@
+import autocomplete_light
+
+from models import Foo, Bar
+
+autocomplete_light.register(Foo)
+autocomplete_light.register(Bar)
@@ -0,0 +1,16 @@
+from django.db import models
+
+
+class Foo(models.Model):
+ name = models.CharField(max_length=100)
+ bar = models.ForeignKey('Bar', related_name='bar_fk')
+
+ def __unicode__(self):
+ return self.name
+
+
+class Bar(models.Model):
+ name = models.CharField(max_length=100)
+
+ def __unicode__(self):
+ return self.name
View
Binary file not shown.
@@ -0,0 +1,23 @@
+from django.contrib import admin
+
+import autocomplete_light
+
+from models import Trip, City, Trip_City
+
+from django.forms.widgets import HiddenInput
+
+class Trip_CityInline(admin.TabularInline):
+ model = Trip_City
+ extra = 1
+ form = autocomplete_light.modelform_factory(Trip_City)
+ sortable_field_name = "order"
+ fields = ['city', 'order']
+
+
+class TripAdmin(admin.ModelAdmin):
+ form = autocomplete_light.modelform_factory(Trip)
+ inlines = [Trip_CityInline]
+
+admin.site.register(Trip, TripAdmin)
+admin.site.register(City)
+
@@ -0,0 +1,6 @@
+import autocomplete_light
+
+from models import City
+
+autocomplete_light.register(City, search_fields=("city",))
+
@@ -0,0 +1,22 @@
+from django.db import models
+
+
+class City(models.Model):
+ city = models.CharField(max_length=100)
+
+ def __unicode__(self):
+ return self.city
+
+
+class Trip_City(models.Model):
+ trip = models.ForeignKey('Trip')
+ city = models.ForeignKey('City')
+ order = models.PositiveSmallIntegerField()
+
+ class Meta:
+ ordering = ('order',)
+
+
+class Trip(models.Model):
+ name = models.CharField(max_length=200)
+ cities = models.ManyToManyField(City, through=Trip_City)
@@ -0,0 +1 @@
+# Create your views here.
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_grappelli.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
@@ -0,0 +1,4 @@
+django-cities-light
+django-autocomplete-light
+django-grappelli
+django-cities-light
Oops, something went wrong.

0 comments on commit b5f5544

Please sign in to comment.