Revision created by MOE tool push_codebase.
[gae.git] / python / lib / django_1_3 / tests / regressiontests / generic_inline_admin / models.py
blobfb6363e2bb7c4bc6559f0d55c9d465c7e371cc9b
1 from django.db import models
2 from django.contrib import admin
3 from django.contrib.contenttypes import generic
4 from django.contrib.contenttypes.models import ContentType
6 class Episode(models.Model):
7 name = models.CharField(max_length=100)
9 class Media(models.Model):
10 """
11 Media that can associated to any object.
12 """
13 content_type = models.ForeignKey(ContentType)
14 object_id = models.PositiveIntegerField()
15 content_object = generic.GenericForeignKey()
16 url = models.URLField(verify_exists=False)
18 def __unicode__(self):
19 return self.url
21 class MediaInline(generic.GenericTabularInline):
22 model = Media
24 class EpisodeAdmin(admin.ModelAdmin):
25 inlines = [
26 MediaInline,
28 admin.site.register(Episode, EpisodeAdmin)
31 # These models let us test the different GenericInline settings at
32 # different urls in the admin site.
36 # Generic inline with extra = 0
39 class EpisodeExtra(Episode):
40 pass
42 class MediaExtraInline(generic.GenericTabularInline):
43 model = Media
44 extra = 0
46 admin.site.register(EpisodeExtra, inlines=[MediaExtraInline])
49 # Generic inline with extra and max_num
52 class EpisodeMaxNum(Episode):
53 pass
55 class MediaMaxNumInline(generic.GenericTabularInline):
56 model = Media
57 extra = 5
58 max_num = 2
60 admin.site.register(EpisodeMaxNum, inlines=[MediaMaxNumInline])
63 # Generic inline with exclude
66 class EpisodeExclude(Episode):
67 pass
69 class MediaExcludeInline(generic.GenericTabularInline):
70 model = Media
71 exclude = ['url']
73 admin.site.register(EpisodeExclude, inlines=[MediaExcludeInline])
76 # Generic inline with unique_together
79 class Category(models.Model):
80 name = models.CharField(max_length=50)
82 class PhoneNumber(models.Model):
83 content_type = models.ForeignKey(ContentType)
84 object_id = models.PositiveIntegerField()
85 content_object = generic.GenericForeignKey('content_type', 'object_id')
86 phone_number = models.CharField(max_length=30)
87 category = models.ForeignKey(Category, null=True, blank=True)
89 class Meta:
90 unique_together = (('content_type', 'object_id', 'phone_number',),)
92 class Contact(models.Model):
93 name = models.CharField(max_length=50)
94 phone_numbers = generic.GenericRelation(PhoneNumber)
96 class PhoneNumberInline(generic.GenericTabularInline):
97 model = PhoneNumber
99 admin.site.register(Contact, inlines=[PhoneNumberInline])
100 admin.site.register(Category)
103 # Generic inline with can_delete=False
106 class EpisodePermanent(Episode):
107 pass
109 class MediaPermanentInline(generic.GenericTabularInline):
110 model = Media
111 can_delete = False
113 admin.site.register(EpisodePermanent, inlines=[MediaPermanentInline])