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