2009-05-03 15:38:36 +02:00
|
|
|
"""
|
|
|
|
Testing of admin inline formsets.
|
|
|
|
|
|
|
|
"""
|
|
|
|
from django.db import models
|
2010-02-23 18:14:50 +01:00
|
|
|
from django.contrib import admin
|
2009-05-03 15:38:36 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
|
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Teacher(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Child(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
teacher = models.ForeignKey(Teacher)
|
|
|
|
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
parent = generic.GenericForeignKey()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'I am %s, a child of %s' % (self.name, self.parent)
|
|
|
|
|
2010-04-27 14:35:49 +02:00
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
books = models.ManyToManyField(Book)
|
|
|
|
|
|
|
|
class BookInline(admin.TabularInline):
|
|
|
|
model = Author.books.through
|
|
|
|
|
|
|
|
class AuthorAdmin(admin.ModelAdmin):
|
|
|
|
inlines = [BookInline]
|
|
|
|
|
|
|
|
admin.site.register(Author, AuthorAdmin)
|
2010-02-23 18:14:50 +01:00
|
|
|
|
|
|
|
class Holder(models.Model):
|
|
|
|
dummy = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class Inner(models.Model):
|
|
|
|
dummy = models.IntegerField()
|
|
|
|
holder = models.ForeignKey(Holder)
|
2010-03-27 00:38:05 +01:00
|
|
|
readonly = models.CharField("Inner readonly label", max_length=1)
|
2010-02-23 18:14:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
class InnerInline(admin.StackedInline):
|
|
|
|
model = Inner
|
|
|
|
can_delete = False
|
2010-03-27 00:38:05 +01:00
|
|
|
readonly_fields = ('readonly',) # For bug #13174 tests.
|
2010-02-23 18:14:50 +01:00
|
|
|
|
|
|
|
|
2010-03-21 02:54:00 +01:00
|
|
|
class Holder2(models.Model):
|
|
|
|
dummy = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class Inner2(models.Model):
|
|
|
|
dummy = models.IntegerField()
|
|
|
|
holder = models.ForeignKey(Holder2)
|
|
|
|
|
|
|
|
class HolderAdmin(admin.ModelAdmin):
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_admin_scripts.js',)
|
|
|
|
|
|
|
|
class InnerInline2(admin.StackedInline):
|
|
|
|
model = Inner2
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_inline_scripts.js',)
|
|
|
|
|
|
|
|
class Holder3(models.Model):
|
|
|
|
dummy = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
class Inner3(models.Model):
|
|
|
|
dummy = models.IntegerField()
|
|
|
|
holder = models.ForeignKey(Holder3)
|
|
|
|
|
|
|
|
class InnerInline3(admin.StackedInline):
|
|
|
|
model = Inner3
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
js = ('my_awesome_inline_scripts.js',)
|
|
|
|
|
|
|
|
# Test bug #12561 and #12778
|
|
|
|
# only ModelAdmin media
|
|
|
|
admin.site.register(Holder, HolderAdmin, inlines=[InnerInline])
|
|
|
|
# ModelAdmin and Inline media
|
|
|
|
admin.site.register(Holder2, HolderAdmin, inlines=[InnerInline2])
|
|
|
|
# only Inline media
|
|
|
|
admin.site.register(Holder3, inlines=[InnerInline3])
|
2010-02-23 18:14:50 +01:00
|
|
|
|
2010-04-27 17:05:38 +02:00
|
|
|
# Models for #12749
|
|
|
|
|
|
|
|
class Person(models.Model):
|
|
|
|
firstname = models.CharField(max_length=15)
|
|
|
|
|
|
|
|
class OutfitItem(models.Model):
|
|
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
|
|
|
class Fashionista(models.Model):
|
|
|
|
person = models.OneToOneField(Person, primary_key=True)
|
|
|
|
weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True)
|
|
|
|
|
|
|
|
class ShoppingWeakness(models.Model):
|
|
|
|
fashionista = models.ForeignKey(Fashionista)
|
|
|
|
item = models.ForeignKey(OutfitItem)
|
|
|
|
|
|
|
|
class InlineWeakness(admin.TabularInline):
|
|
|
|
model = ShoppingWeakness
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
admin.site.register(Fashionista, inlines=[InlineWeakness])
|