2008-08-28 23:43:04 +08:00
|
|
|
"""
|
|
|
|
Tests of ModelAdmin validation logic.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
2009-10-20 03:17:07 +08:00
|
|
|
|
2009-05-03 21:39:33 +08:00
|
|
|
class Album(models.Model):
|
|
|
|
title = models.CharField(max_length=150)
|
|
|
|
|
2009-10-20 03:17:07 +08:00
|
|
|
|
2008-08-28 23:43:04 +08:00
|
|
|
class Song(models.Model):
|
|
|
|
title = models.CharField(max_length=150)
|
2009-05-03 21:39:33 +08:00
|
|
|
album = models.ForeignKey(Album)
|
2010-03-09 04:36:37 +08:00
|
|
|
original_release = models.DateField(editable=False)
|
2009-05-03 21:39:33 +08:00
|
|
|
|
2008-08-28 23:43:04 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
2009-05-03 21:39:33 +08:00
|
|
|
|
2008-08-28 23:43:04 +08:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
|
|
|
|
2009-12-23 02:29:00 +08:00
|
|
|
def readonly_method_on_model(self):
|
|
|
|
# does nothing
|
|
|
|
pass
|
|
|
|
|
2009-10-20 03:17:07 +08:00
|
|
|
|
2009-10-20 03:17:20 +08:00
|
|
|
class TwoAlbumFKAndAnE(models.Model):
|
2009-10-20 03:17:07 +08:00
|
|
|
album1 = models.ForeignKey(Album, related_name="album1_set")
|
|
|
|
album2 = models.ForeignKey(Album, related_name="album2_set")
|
|
|
|
e = models.CharField(max_length=1)
|
|
|
|
|
|
|
|
|
2009-11-13 20:34:41 +08:00
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2009-11-19 23:07:42 +08:00
|
|
|
subtitle = models.CharField(max_length=100)
|
|
|
|
price = models.FloatField()
|
2009-11-13 20:34:41 +08:00
|
|
|
authors = models.ManyToManyField(Author, through='AuthorsBooks')
|
|
|
|
|
|
|
|
|
|
|
|
class AuthorsBooks(models.Model):
|
|
|
|
author = models.ForeignKey(Author)
|
|
|
|
book = models.ForeignKey(Book)
|
2011-02-26 09:44:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
|
|
|
|
|
|
|
class City(models.Model):
|
|
|
|
state = models.ForeignKey(State)
|