Debian Codegraph @

tests/admin_filters/models.py

raw
1 from django.contrib.auth.models import User
2 from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
3 from django.contrib.contenttypes.models import ContentType
4 from django.db import models
5
6
7 class Book(models.Model):
8 title = models.CharField(max_length=50)
9 year = models.PositiveIntegerField(null=True, blank=True)
10 author = models.ForeignKey(
11 User,
12 models.SET_NULL,
13 verbose_name="Verbose Author",
14 related_name="books_authored",
15 blank=True,
16 null=True,
17 )
18 contributors = models.ManyToManyField(
19 User,
20 verbose_name="Verbose Contributors",
21 related_name="books_contributed",
22 blank=True,
23 )
24 employee = models.ForeignKey(
25 "Employee",
26 models.SET_NULL,
27 verbose_name="Employee",
28 blank=True,
29 null=True,
30 )
31 is_best_seller = models.BooleanField(default=0, null=True)
32 date_registered = models.DateField(null=True)
33 availability = models.BooleanField(
34 choices=(
35 (False, "Paid"),
36 (True, "Free"),
37 (None, "Obscure"),
38 ),
39 null=True,
40 )
41 # This field name is intentionally 2 characters long (#16080).
42 no = models.IntegerField(verbose_name="number", blank=True, null=True)
43 CHOICES = [
44 ("non-fiction", "Non-Fictional"),
45 ("fiction", "Fictional"),
46 (None, "Not categorized"),
47 ("", "We don't know"),
48 ]
49 category = models.CharField(max_length=20, choices=CHOICES, blank=True, null=True)
50
51 def __str__(self):
52 return self.title
53
54
55 class ImprovedBook(models.Model):
56 book = models.OneToOneField(Book, models.CASCADE)
57
58
59 class Department(models.Model):
60 code = models.CharField(max_length=4, unique=True)
61 description = models.CharField(max_length=50, blank=True, null=True)
62
63 def __str__(self):
64 return self.description
65
66
67 class Employee(models.Model):
68 department = models.ForeignKey(Department, models.CASCADE, to_field="code")
69 name = models.CharField(max_length=100)
70
71 def __str__(self):
72 return self.name
73
74
75 class TaggedItem(models.Model):
76 tag = models.SlugField()
77 content_type = models.ForeignKey(
78 ContentType, models.CASCADE, related_name="tagged_items"
79 )
80 object_id = models.PositiveIntegerField()
81 content_object = GenericForeignKey("content_type", "object_id")
82
83 def __str__(self):
84 return self.tag
85
86
87 class Bookmark(models.Model):
88 url = models.URLField()
89 tags = GenericRelation(TaggedItem)
90
91 CHOICES = [
92 ("a", "A"),
93 (None, "None"),
94 ("", "-"),
95 ]
96 none_or_null = models.CharField(
97 max_length=20, choices=CHOICES, blank=True, null=True
98 )
99
100 def __str__(self):
101 return self.url