| 1 |
""" |
| 2 |
Tests of ModelAdmin system checks logic. |
| 3 |
""" |
| 4 |
|
| 5 |
from django.contrib.contenttypes.fields import GenericForeignKey |
| 6 |
from django.contrib.contenttypes.models import ContentType |
| 7 |
from django.db import models |
| 8 |
|
| 9 |
|
| 10 |
class Album(models.Model): |
| 11 |
title = models.CharField(max_length=150) |
| 12 |
|
| 13 |
|
| 14 |
class Song(models.Model): |
| 15 |
title = models.CharField(max_length=150) |
| 16 |
album = models.ForeignKey(Album, models.CASCADE) |
| 17 |
original_release = models.DateField(editable=False) |
| 18 |
|
| 19 |
class Meta: |
| 20 |
ordering = ("title",) |
| 21 |
|
| 22 |
def __str__(self): |
| 23 |
return self.title |
| 24 |
|
| 25 |
def readonly_method_on_model(self): |
| 26 |
# does nothing |
| 27 |
pass |
| 28 |
|
| 29 |
|
| 30 |
class TwoAlbumFKAndAnE(models.Model): |
| 31 |
album1 = models.ForeignKey(Album, models.CASCADE, related_name="album1_set") |
| 32 |
album2 = models.ForeignKey(Album, models.CASCADE, related_name="album2_set") |
| 33 |
e = models.CharField(max_length=1) |
| 34 |
|
| 35 |
|
| 36 |
class Author(models.Model): |
| 37 |
name = models.CharField(max_length=100) |
| 38 |
|
| 39 |
|
| 40 |
class Book(models.Model): |
| 41 |
name = models.CharField(max_length=100) |
| 42 |
subtitle = models.CharField(max_length=100) |
| 43 |
price = models.FloatField() |
| 44 |
authors = models.ManyToManyField(Author, through="AuthorsBooks") |
| 45 |
|
| 46 |
|
| 47 |
class AuthorsBooks(models.Model): |
| 48 |
author = models.ForeignKey(Author, models.CASCADE) |
| 49 |
book = models.ForeignKey(Book, models.CASCADE) |
| 50 |
featured = models.BooleanField() |
| 51 |
|
| 52 |
|
| 53 |
class State(models.Model): |
| 54 |
name = models.CharField(max_length=15) |
| 55 |
|
| 56 |
|
| 57 |
class City(models.Model): |
| 58 |
state = models.ForeignKey(State, models.CASCADE) |
| 59 |
|
| 60 |
|
| 61 |
class Influence(models.Model): |
| 62 |
name = models.TextField() |
| 63 |
|
| 64 |
content_type = models.ForeignKey(ContentType, models.CASCADE) |
| 65 |
object_id = models.PositiveIntegerField() |
| 66 |
content_object = GenericForeignKey("content_type", "object_id") |