~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/regressiontests/admin_inlines/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
"""
5
5
from django.db import models
 
6
from django.contrib import admin
6
7
from django.contrib.contenttypes.models import ContentType
7
8
from django.contrib.contenttypes import generic
8
9
 
29
30
    def __unicode__(self):
30
31
        return u'I am %s, a child of %s' % (self.name, self.parent)
31
32
 
 
33
class Book(models.Model):
 
34
    name = models.CharField(max_length=50)
 
35
 
 
36
class Author(models.Model):
 
37
    name = models.CharField(max_length=50)
 
38
    books = models.ManyToManyField(Book)
 
39
 
 
40
class BookInline(admin.TabularInline):
 
41
    model = Author.books.through
 
42
 
 
43
class AuthorAdmin(admin.ModelAdmin):
 
44
    inlines = [BookInline]
 
45
 
 
46
admin.site.register(Author, AuthorAdmin)
 
47
 
 
48
class Holder(models.Model):
 
49
    dummy = models.IntegerField()
 
50
 
 
51
 
 
52
class Inner(models.Model):
 
53
    dummy = models.IntegerField()
 
54
    holder = models.ForeignKey(Holder)
 
55
    readonly = models.CharField("Inner readonly label", max_length=1)
 
56
 
 
57
 
 
58
class InnerInline(admin.StackedInline):
 
59
    model = Inner
 
60
    can_delete = False
 
61
    readonly_fields = ('readonly',) # For bug #13174 tests.
 
62
 
 
63
 
 
64
class Holder2(models.Model):
 
65
    dummy = models.IntegerField()
 
66
 
 
67
 
 
68
class Inner2(models.Model):
 
69
    dummy = models.IntegerField()
 
70
    holder = models.ForeignKey(Holder2)
 
71
 
 
72
class HolderAdmin(admin.ModelAdmin):
 
73
 
 
74
    class Media:
 
75
        js = ('my_awesome_admin_scripts.js',)
 
76
 
 
77
class InnerInline2(admin.StackedInline):
 
78
    model = Inner2
 
79
 
 
80
    class Media:
 
81
        js = ('my_awesome_inline_scripts.js',)
 
82
 
 
83
class Holder3(models.Model):
 
84
    dummy = models.IntegerField()
 
85
 
 
86
 
 
87
class Inner3(models.Model):
 
88
    dummy = models.IntegerField()
 
89
    holder = models.ForeignKey(Holder3)
 
90
 
 
91
class InnerInline3(admin.StackedInline):
 
92
    model = Inner3
 
93
 
 
94
    class Media:
 
95
        js = ('my_awesome_inline_scripts.js',)
 
96
 
 
97
# Test bug #12561 and #12778
 
98
# only ModelAdmin media
 
99
admin.site.register(Holder, HolderAdmin, inlines=[InnerInline])
 
100
# ModelAdmin and Inline media
 
101
admin.site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
 
102
# only Inline media
 
103
admin.site.register(Holder3, inlines=[InnerInline3])
 
104
 
 
105
# Models for #12749
 
106
 
 
107
class Person(models.Model):
 
108
    firstname = models.CharField(max_length=15)
 
109
 
 
110
class OutfitItem(models.Model):
 
111
    name = models.CharField(max_length=15)
 
112
 
 
113
class Fashionista(models.Model):
 
114
    person = models.OneToOneField(Person, primary_key=True)
 
115
    weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True)
 
116
 
 
117
class ShoppingWeakness(models.Model):
 
118
    fashionista = models.ForeignKey(Fashionista)
 
119
    item = models.ForeignKey(OutfitItem)
 
120
 
 
121
class InlineWeakness(admin.TabularInline):
 
122
    model = ShoppingWeakness
 
123
    extra = 1
 
124
 
 
125
admin.site.register(Fashionista, inlines=[InlineWeakness])
 
126
 
 
127
 
32
128
__test__ = {'API_TESTS': """
33
129
 
34
130
# Regression test for #9362
48
144
<Child: I am Joe, a child of John>
49
145
 
50
146
"""
51
 
}
 
 
b'\\ No newline at end of file'
 
147
}