Debian Codegraph @

tests/modeladmin/models.py

raw
1 from django.contrib.auth.models import User
2 from django.db import models
3
4
5 class Band(models.Model):
6 name = models.CharField(max_length=100)
7 bio = models.TextField()
8 sign_date = models.DateField()
9
10 class Meta:
11 ordering = ("name",)
12
13 def __str__(self):
14 return self.name
15
16
17 class Song(models.Model):
18 name = models.CharField(max_length=100)
19 band = models.ForeignKey(Band, models.CASCADE)
20 featuring = models.ManyToManyField(Band, related_name="featured")
21
22 def __str__(self):
23 return self.name
24
25
26 class Concert(models.Model):
27 main_band = models.ForeignKey(Band, models.CASCADE, related_name="main_concerts")
28 opening_band = models.ForeignKey(
29 Band, models.CASCADE, related_name="opening_concerts", blank=True
30 )
31 day = models.CharField(max_length=3, choices=((1, "Fri"), (2, "Sat")))
32 transport = models.CharField(
33 max_length=100, choices=((1, "Plane"), (2, "Train"), (3, "Bus")), blank=True
34 )
35
36
37 class ValidationTestModel(models.Model):
38 name = models.CharField(max_length=100)
39 slug = models.SlugField()
40 users = models.ManyToManyField(User)
41 state = models.CharField(
42 max_length=2, choices=(("CO", "Colorado"), ("WA", "Washington"))
43 )
44 is_active = models.BooleanField(default=False)
45 pub_date = models.DateTimeField()
46 band = models.ForeignKey(Band, models.CASCADE)
47 best_friend = models.OneToOneField(User, models.CASCADE, related_name="best_friend")
48 # This field is intentionally 2 characters long (#16080).
49 no = models.IntegerField(verbose_name="Number", blank=True, null=True)
50
51 def decade_published_in(self):
52 return self.pub_date.strftime("%Y")[:3] + "0's"
53
54
55 class ValidationTestInlineModel(models.Model):
56 parent = models.ForeignKey(ValidationTestModel, models.CASCADE)