Permalink
Browse files

more example models

  • Loading branch information...
stefanfoulis committed Oct 9, 2011
1 parent 14966b8 commit 6011ffc6e462797fb634400a5ff3120c8bdcc8b9
Showing with 32 additions and 11 deletions.
  1. +15 −11 widgetry_example/admin.py
  2. +17 −0 widgetry_example/models.py
View
@@ -1,28 +1,26 @@
#-*- coding: utf-8 -*-
from django.db import models
from django.contrib import admin
-from django.contrib.admin.options import TabularInline, StackedInline
+from django.contrib.admin.options import TabularInline
from widgetry.fk_lookup.widgets import FkLookup
from widgetry_example.models import SimpleModel, SimpleInlineModel, AnotherSimpleInlineModel, Foo
from widgetry.tabs.admin import ModelAdminWithTabs
-class SimpleModelAdmin(admin.ModelAdmin):
- pass
-admin.site.register(SimpleModel, SimpleModelAdmin)
-
-
-class SimpleModel2(SimpleModel):
+class SimpleModelDefault(SimpleModel):
class Meta:
proxy = True
+admin.site.register(SimpleModelDefault)
class SimpleModelInlineAdmin(TabularInline):
model = SimpleInlineModel
+ extra = 0
-class AnotherSimpleModelInlineAdmin(StackedInline):
+class AnotherSimpleModelInlineAdmin(TabularInline):
model = AnotherSimpleInlineModel
+ extra = 0
class SimpleModelAdmin(ModelAdminWithTabs):
@@ -46,6 +44,14 @@ class SimpleModelAdmin(ModelAdminWithTabs):
]
}),
)
+admin.site.register(SimpleModel, SimpleModelAdmin)
+
+
+class SimpleModelWithFKLookup(SimpleModel):
+ class Meta:
+ proxy = True
+
+class TabsWithFkLookupModelAdmin(SimpleModelAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
"""
Overrides the default widget for Foreignkey fields if they are
@@ -54,8 +60,6 @@ def formfield_for_dbfield(self, db_field, **kwargs):
if isinstance(db_field, models.ForeignKey):
kwargs['widget'] = FkLookup(db_field.rel.to)
return super(SimpleModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
-
-
-admin.site.register(SimpleModel2, SimpleModelAdmin)
+admin.site.register(SimpleModelWithFKLookup, TabsWithFkLookupModelAdmin)
admin.site.register(Foo)
View
@@ -1,6 +1,23 @@
#-*- coding: utf-8 -*-
from django.db import models
from widgetry.views import search
+from django.contrib.auth.models import User
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.contenttypes import generic
+
+class Avatar(models.Model):
+ user = models.ForeignKey(User)
+ image = models.ImageField(upload_to='avatars')
+
+
+class Link(models.Model):
+ name = models.CharField(max_length=255)
+ content_type = models.ForeignKey(ContentType)
+ object_id = models.PositiveIntegerField()
+ content_object = generic.GenericForeignKey('content_type', 'object_id')
+
+ def __unicode__(self):
+ return self.name
class SimpleModel(models.Model):

0 comments on commit 6011ffc

Please sign in to comment.