2014-01-20 10:45:21 +08:00
|
|
|
"""
|
|
|
|
Tests of ModelAdmin system checks logic.
|
|
|
|
"""
|
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2014-01-20 10:45:21 +08:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
|
2014-03-09 08:17:54 +08:00
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
class Album(models.Model):
|
|
|
|
title = models.CharField(max_length=150)
|
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Song(models.Model):
|
|
|
|
title = models.CharField(max_length=150)
|
2015-07-22 22:43:21 +08:00
|
|
|
album = models.ForeignKey(Album, models.CASCADE)
|
2014-01-20 10:45:21 +08:00
|
|
|
original_release = models.DateField(editable=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def readonly_method_on_model(self):
|
|
|
|
# does nothing
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class TwoAlbumFKAndAnE(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
album1 = models.ForeignKey(Album, models.CASCADE, related_name="album1_set")
|
|
|
|
album2 = models.ForeignKey(Album, models.CASCADE, related_name="album2_set")
|
2014-01-20 10:45:21 +08:00
|
|
|
e = models.CharField(max_length=1)
|
|
|
|
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
subtitle = models.CharField(max_length=100)
|
|
|
|
price = models.FloatField()
|
|
|
|
authors = models.ManyToManyField(Author, through='AuthorsBooks')
|
|
|
|
|
|
|
|
|
|
|
|
class AuthorsBooks(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
author = models.ForeignKey(Author, models.CASCADE)
|
|
|
|
book = models.ForeignKey(Book, models.CASCADE)
|
2015-02-11 01:15:54 +08:00
|
|
|
featured = models.BooleanField()
|
2014-01-20 10:45:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
|
|
|
|
|
|
|
class City(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
state = models.ForeignKey(State, models.CASCADE)
|
2014-03-08 11:24:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Influence(models.Model):
|
|
|
|
name = models.TextField()
|
|
|
|
|
2015-07-22 22:43:21 +08:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2014-03-08 11:24:13 +08:00
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = GenericForeignKey('content_type', 'object_id')
|