Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Nov 28th, 2010  |  syntax: Python  |  size: 0.72 KB  |  hits: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Note that this is untested.
  2.  
  3.  
  4. models.py:
  5.  
  6. class Title(models.Model):
  7.     title = models.CharField("Title", max_length=200)
  8.     content_type = models.ForeignKey(ContentType)
  9.     object_id = models.PositiveIntegerField()
  10.     content_object = generic.GenericForeignKey("content_type", "object_id")
  11.    
  12.     class Meta:
  13.         unique_together = ['content_type', 'object_id']
  14.  
  15.  
  16. class Category(models.Model):
  17.     def get_title(self):
  18.         return Title.objects.get(content_type=self.__class__, object_id=self.id)
  19.  
  20.  
  21.  
  22. admin.py:
  23.  
  24. class TitleInline(generic.GenericTabularInline):
  25.     model = Title
  26.  
  27. class CategoryAdmin(admin.ModelAdmin):
  28.     inlines = [TitleInline]
  29.  
  30. admin.site.register(Category, CategoryAdmin)