[d7662b5] | 1 | from django.db import models
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | class 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 |
|
---|
| 15 | class 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 |
|
---|
| 27 | class 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 |
|
---|
| 51 | class 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 |
|
---|
| 73 | class 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 |
|
---|
| 84 | class 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 |
|
---|
| 95 | class 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 |
|
---|
| 113 | class Invoice(models.Model):
|
---|
| 114 | invoice_id = models.AutoField(primary_key=True)
|
---|
| 115 | customer = models.ForeignKey(Customer, on_delete=models.CASCADE, db_column='customer_id')
|
---|
| 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 |
|
---|
| 130 |
|
---|
| 131 | class InvoiceLine(models.Model):
|
---|
| 132 | invoice_line_id = models.AutoField(primary_key=True)
|
---|
| 133 | invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE, db_column='invoice_id')
|
---|
| 134 | track = models.ForeignKey(Track, on_delete=models.CASCADE, db_column='track_id')
|
---|
| 135 | unit_price = models.DecimalField(max_digits=10, decimal_places=2)
|
---|
| 136 | quantity = models.IntegerField()
|
---|
| 137 |
|
---|
| 138 | class Meta:
|
---|
| 139 | db_table = 'invoice_line'
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | class Playlist(models.Model):
|
---|
| 143 | playlist_id = models.AutoField(primary_key=True)
|
---|
| 144 | name = models.CharField(max_length=120, blank=True, null=True)
|
---|
| 145 |
|
---|
| 146 | def __str__(self):
|
---|
| 147 | return self.name or f"Playlist {self.playlist_id}"
|
---|
| 148 |
|
---|
| 149 | class Meta:
|
---|
| 150 | db_table = 'playlist'
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | class PlaylistTrack(models.Model):
|
---|
| 154 | id = models.AutoField(primary_key=True)
|
---|
| 155 | playlist = models.ForeignKey(Playlist, on_delete=models.CASCADE, db_column='playlist_id')
|
---|
| 156 | track = models.ForeignKey(Track, on_delete=models.CASCADE, db_column='track_id')
|
---|
| 157 |
|
---|
| 158 | class Meta:
|
---|
| 159 | db_table = 'playlist_track'
|
---|
| 160 | managed = False
|
---|
| 161 | unique_together = (('playlist', 'track'),)
|
---|
| 162 |
|
---|
| 163 | def __str__(self):
|
---|
| 164 | return f"{self.playlist} - {self.track}"
|
---|