2008-08-28 17:43:04 +02:00
|
|
|
"""
|
|
|
|
Tests of ModelAdmin validation logic.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-08-28 17:43:04 +02:00
|
|
|
|
2009-10-19 21:17:07 +02:00
|
|
|
|
2009-05-03 15:39:33 +02:00
|
|
|
class Album(models.Model):
|
|
|
|
title = models.CharField(max_length=150)
|
|
|
|
|
2009-10-19 21:17:07 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2008-08-28 17:43:04 +02:00
|
|
|
class Song(models.Model):
|
|
|
|
title = models.CharField(max_length=150)
|
2009-05-03 15:39:33 +02:00
|
|
|
album = models.ForeignKey(Album)
|
2010-03-08 21:36:37 +01:00
|
|
|
original_release = models.DateField(editable=False)
|
2009-05-03 15:39:33 +02:00
|
|
|
|
2008-08-28 17:43:04 +02:00
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
2009-05-03 15:39:33 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2008-08-28 17:43:04 +02:00
|
|
|
return self.title
|
|
|
|
|
2009-12-22 19:29:00 +01:00
|
|
|
def readonly_method_on_model(self):
|
|
|
|
# does nothing
|
|
|
|
pass
|
|
|
|
|
2009-10-19 21:17:07 +02:00
|
|
|
|
2009-10-19 21:17:20 +02:00
|
|
|
class TwoAlbumFKAndAnE(models.Model):
|
2009-10-19 21:17:07 +02: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 13:34:41 +01:00
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2009-11-19 16:07:42 +01:00
|
|
|
subtitle = models.CharField(max_length=100)
|
|
|
|
price = models.FloatField()
|
2009-11-13 13:34:41 +01:00
|
|
|
authors = models.ManyToManyField(Author, through='AuthorsBooks')
|
|
|
|
|
|
|
|
|
|
|
|
class AuthorsBooks(models.Model):
|
|
|
|
author = models.ForeignKey(Author)
|
|
|
|
book = models.ForeignKey(Book)
|
2011-02-26 02:44:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
|
|
|
|
|
|
|
class City(models.Model):
|
|
|
|
state = models.ForeignKey(State)
|