source: music/models.py

Last change on this file was 75ea229, checked in by ManuelTrajcev <manueltrajcev7@…>, 5 days ago

update

  • Property mode set to 100644
File size: 6.9 KB
Line 
1from django.db import models
2
3
4class Artist(models.Model):
5 artist_id = models.AutoField(primary_key=True)
6 name = models.CharField(max_length=120, blank=True, null=True)
7
8 def __str__(self):
9 return self.name or "Unknown Artist"
10
11 class Meta:
12 db_table = 'artist'
13
14
15class Album(models.Model):
16 album_id = models.AutoField(primary_key=True)
17 title = models.CharField(max_length=160)
18 artist = models.ForeignKey(Artist, on_delete=models.CASCADE, db_column='artist_id')
19
20 def __str__(self):
21 return self.title
22
23 class Meta:
24 db_table = 'album'
25
26
27class Employee(models.Model):
28 employee_id = models.AutoField(primary_key=True)
29 last_name = models.CharField(max_length=20)
30 first_name = models.CharField(max_length=20)
31 title = models.CharField(max_length=30, blank=True, null=True)
32 reports_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, db_column='reports_to')
33 birth_date = models.DateTimeField(blank=True, null=True)
34 hire_date = models.DateTimeField(blank=True, null=True)
35 address = models.CharField(max_length=70, blank=True, null=True)
36 city = models.CharField(max_length=40, blank=True, null=True)
37 state = models.CharField(max_length=40, blank=True, null=True)
38 country = models.CharField(max_length=40, blank=True, null=True)
39 postal_code = models.CharField(max_length=10, blank=True, null=True)
40 phone = models.CharField(max_length=24, blank=True, null=True)
41 fax = models.CharField(max_length=24, blank=True, null=True)
42 email = models.CharField(max_length=60, blank=True, null=True)
43
44 def __str__(self):
45 return f"{self.first_name} {self.last_name}"
46
47 class Meta:
48 db_table = 'employee'
49
50
51class Customer(models.Model):
52 customer_id = models.AutoField(primary_key=True)
53 first_name = models.CharField(max_length=40)
54 last_name = models.CharField(max_length=20)
55 company = models.CharField(max_length=80, blank=True, null=True)
56 address = models.CharField(max_length=70, blank=True, null=True)
57 city = models.CharField(max_length=40, blank=True, null=True)
58 state = models.CharField(max_length=40, blank=True, null=True)
59 country = models.CharField(max_length=40, blank=True, null=True)
60 postal_code = models.CharField(max_length=10, blank=True, null=True)
61 phone = models.CharField(max_length=24, blank=True, null=True)
62 fax = models.CharField(max_length=24, blank=True, null=True)
63 email = models.CharField(max_length=60)
64 support_rep = models.ForeignKey(Employee, on_delete=models.SET_NULL, blank=True, null=True, db_column='support_rep_id')
65
66 def __str__(self):
67 return f"{self.first_name} {self.last_name}"
68
69 class Meta:
70 db_table = 'customer'
71
72
73class Genre(models.Model):
74 genre_id = models.AutoField(primary_key=True)
75 name = models.CharField(max_length=120, blank=True, null=True)
76
77 def __str__(self):
78 return self.name or "Unknown Genre"
79
80 class Meta:
81 db_table = 'genre'
82
83
84class MediaType(models.Model):
85 media_type_id = models.AutoField(primary_key=True)
86 name = models.CharField(max_length=120, blank=True, null=True)
87
88 def __str__(self):
89 return self.name or "Unknown Media"
90
91 class Meta:
92 db_table = 'media_type'
93
94
95class Track(models.Model):
96 track_id = models.AutoField(primary_key=True)
97 name = models.CharField(max_length=200)
98 album = models.ForeignKey(Album, on_delete=models.SET_NULL, blank=True, null=True, db_column='album_id')
99 media_type = models.ForeignKey(MediaType, on_delete=models.CASCADE, db_column='media_type_id')
100 genre = models.ForeignKey(Genre, on_delete=models.SET_NULL, blank=True, null=True, db_column='genre_id')
101 composer = models.CharField(max_length=220, blank=True, null=True)
102 milliseconds = models.IntegerField()
103 bytes = models.IntegerField(blank=True, null=True)
104 unit_price = models.DecimalField(max_digits=10, decimal_places=2)
105
106 def __str__(self):
107 return self.name
108
109 class Meta:
110 db_table = 'track'
111
112
113class Invoice(models.Model):
114 invoice_id = models.AutoField(primary_key=True)
115 customer = models.ForeignKey(Customer, on_delete=models.SET_NULL, db_column='customer_id', null=True)
116 invoice_date = models.DateTimeField()
117 billing_address = models.CharField(max_length=70, blank=True, null=True)
118 billing_city = models.CharField(max_length=40, blank=True, null=True)
119 billing_state = models.CharField(max_length=40, blank=True, null=True)
120 billing_country = models.CharField(max_length=40, blank=True, null=True)
121 billing_postal_code = models.CharField(max_length=10, blank=True, null=True)
122 total = models.DecimalField(max_digits=10, decimal_places=2)
123
124 def __str__(self):
125 return f"Invoice #{self.invoice_id}"
126
127 class Meta:
128 db_table = 'invoice'
129 managed = False
130
131
132class InvoiceLine(models.Model):
133 invoice_line_id = models.AutoField(primary_key=True)
134 invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE, db_column='invoice_id')
135 track = models.ForeignKey(Track, on_delete=models.CASCADE, db_column='track_id')
136 unit_price = models.DecimalField(max_digits=10, decimal_places=2)
137 quantity = models.IntegerField()
138
139 class Meta:
140 db_table = 'invoice_line'
141 managed = False
142
143
144class Playlist(models.Model):
145 playlist_id = models.AutoField(primary_key=True)
146 name = models.CharField(max_length=120, blank=True, null=True)
147
148 def __str__(self):
149 return self.name or f"Playlist {self.playlist_id}"
150
151 class Meta:
152 db_table = 'playlist'
153
154
155class PlaylistTrack(models.Model):
156 id = models.AutoField(primary_key=True)
157 playlist = models.ForeignKey(Playlist, on_delete=models.CASCADE, db_column='playlist_id')
158 track = models.ForeignKey(Track, on_delete=models.CASCADE, db_column='track_id')
159
160 class Meta:
161 db_table = 'playlist_track'
162 managed = False
163 unique_together = (('playlist', 'track'),)
164
165 def __str__(self):
166 return f"{self.playlist} - {self.track}"
167
168
169class DeletedCustomerLog(models.Model):
170 log_id = models.AutoField(primary_key=True)
171 first_name = models.CharField(max_length=40)
172 last_name = models.CharField(max_length=20)
173 deleted_at = models.DateTimeField()
174 total_spent = models.DecimalField(max_digits=10, decimal_places=2)
175 invoice_count = models.IntegerField()
176 class Meta:
177 db_table = 'deleted_customer_log'
178 managed = False
179
180 def __str__(self):
181 return f"{self.first_name} {self.last_name} - Deleted on {self.deleted_at} - Total Spent: ${self.total_spent} from {self.invoice_count} invoices"
182
183class Price(models.Model):
184 price_id = models.AutoField(primary_key=True)
185 value = models.DecimalField(max_digits=10, decimal_places=2)
186 date = models.DateTimeField()
187 track_id = models.ForeignKey(Track, on_delete=models.DO_NOTHING, db_column='track_id')
188
189 class Meta:
190 managed = False
191 db_table = 'price'
192
193 def __str__(self):
194 return f"{self.track_id} - {self.value} - {self.date}"
Note: See TracBrowser for help on using the repository browser.