Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(AbstractUser):
- USERNAME_FIELD = 'email'
- def __str__(self):
- return f'{self.email}, #{self.id}'
- class Subscription(models.Model):
- author_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
- author_id = models.PositiveIntegerField()
- author_object = GenericForeignKey('author_type', 'author_id')
- subscriber = models.ForeignKey(AUTH_USER_MODEL, related_name='subscriptions',
- on_delete=models.CASCADE)
- datetime_committed = models.DateTimeField(auto_now_add=True)
- class Meta:
- ordering = ['-datetime_committed']
- class Notification(models.Model):
- content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
- object_id = models.PositiveIntegerField()
- content_object = GenericForeignKey('content_type', 'object_id')
- creation_date_time = models.DateTimeField(auto_now_add=True)
- def __str__(self):
- return f'Оповещение о новом релизе {self.content_object.name}'
- class Meta:
- ordering = ['-creation_date_time']
- class Artist(models.Model):
- name = models.CharField(max_length=256)
- spotify_id = models.CharField(max_length=256, unique=True)
- subscription = GenericRelation(Subscription, related_query_name='artist')
- def __str__(self):
- return f'{self.name}, #{self.pk}'
- class Album(models.Model):
- album_types = (
- ('album', 'album'),
- ('single', 'single')
- )
- name = models.CharField(max_length=256)
- spotify_id = models.CharField(max_length=256, unique=True)
- release_date = models.DateField()
- notification = GenericRelation(Notification, related_query_name='album')
- def __str__(self):
- return f'{self.name}, #{self.pk}'
- class Meta:
- ordering = ['-release_date']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement