Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more example models

  • Loading branch information...
commit 6011ffc6e462797fb634400a5ff3120c8bdcc8b9 1 parent 14966b8
Stefan Foulis authored October 09, 2011
26  widgetry_example/admin.py
... ...
@@ -1,28 +1,26 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 from django.db import models
3 3
 from django.contrib import admin
4  
-from django.contrib.admin.options import TabularInline, StackedInline
  4
+from django.contrib.admin.options import TabularInline
5 5
 from widgetry.fk_lookup.widgets import FkLookup
6 6
 from widgetry_example.models import SimpleModel, SimpleInlineModel, AnotherSimpleInlineModel, Foo
7 7
 from widgetry.tabs.admin import ModelAdminWithTabs
8 8
 
9 9
 
10  
-class SimpleModelAdmin(admin.ModelAdmin):
11  
-    pass
12  
-admin.site.register(SimpleModel, SimpleModelAdmin)
13  
-
14  
-
15  
-class SimpleModel2(SimpleModel):
  10
+class SimpleModelDefault(SimpleModel):
16 11
     class Meta:
17 12
         proxy = True
  13
+admin.site.register(SimpleModelDefault)
18 14
 
19 15
 
20 16
 class SimpleModelInlineAdmin(TabularInline):
21 17
     model = SimpleInlineModel
  18
+    extra = 0
22 19
 
23 20
 
24  
-class AnotherSimpleModelInlineAdmin(StackedInline):
  21
+class AnotherSimpleModelInlineAdmin(TabularInline):
25 22
     model = AnotherSimpleInlineModel
  23
+    extra = 0
26 24
 
27 25
 
28 26
 class SimpleModelAdmin(ModelAdminWithTabs):
@@ -46,6 +44,14 @@ class SimpleModelAdmin(ModelAdminWithTabs):
46 44
             ]
47 45
         }),
48 46
     )
  47
+admin.site.register(SimpleModel, SimpleModelAdmin)
  48
+
  49
+
  50
+class SimpleModelWithFKLookup(SimpleModel):
  51
+    class Meta:
  52
+        proxy = True
  53
+
  54
+class TabsWithFkLookupModelAdmin(SimpleModelAdmin):
49 55
     def formfield_for_dbfield(self, db_field, **kwargs):
50 56
         """
51 57
         Overrides the default widget for Foreignkey fields if they are
@@ -54,8 +60,6 @@ def formfield_for_dbfield(self, db_field, **kwargs):
54 60
         if isinstance(db_field, models.ForeignKey):
55 61
             kwargs['widget'] = FkLookup(db_field.rel.to)
56 62
         return super(SimpleModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
57  
-
58  
-
59  
-admin.site.register(SimpleModel2, SimpleModelAdmin)
  63
+admin.site.register(SimpleModelWithFKLookup, TabsWithFkLookupModelAdmin)
60 64
 
61 65
 admin.site.register(Foo)
17  widgetry_example/models.py
... ...
@@ -1,6 +1,23 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 from django.db import models
3 3
 from widgetry.views import search
  4
+from django.contrib.auth.models import User
  5
+from django.contrib.contenttypes.models import ContentType
  6
+from django.contrib.contenttypes import generic
  7
+
  8
+class Avatar(models.Model):
  9
+    user = models.ForeignKey(User)
  10
+    image = models.ImageField(upload_to='avatars')
  11
+
  12
+
  13
+class Link(models.Model):
  14
+    name = models.CharField(max_length=255)
  15
+    content_type = models.ForeignKey(ContentType)
  16
+    object_id = models.PositiveIntegerField()
  17
+    content_object = generic.GenericForeignKey('content_type', 'object_id')
  18
+
  19
+    def __unicode__(self):
  20
+        return self.name
4 21
 
5 22
 
6 23
 class SimpleModel(models.Model):

0 notes on commit 6011ffc

Please sign in to comment.
Something went wrong with that request. Please try again.