mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-12-22 13:02:49 -08:00
refactor audio models
This commit is contained in:
parent
b4634179ce
commit
ed26d99177
@ -17,13 +17,14 @@ def slugify_file_name(instance, filename):
|
||||
return f'{slug}.{extension}'
|
||||
|
||||
|
||||
class Feed(UUIDAsIDModel):
|
||||
class EpisodeAndFeed(UUIDAsIDModel):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
created_on = models.DateTimeField(auto_now_add=True)
|
||||
title = models.CharField(max_length=255)
|
||||
author = models.CharField(max_length=255)
|
||||
title = models.CharField(max_length=255)
|
||||
created_on = models.DateTimeField(auto_now_add=True)
|
||||
slug = models.SlugField(max_length=255, unique=True)
|
||||
description = models.TextField(null=False)
|
||||
|
||||
image = models.ImageField(
|
||||
storage=PublicImageStorage(),
|
||||
upload_to=slugify_file_name,
|
||||
@ -33,6 +34,7 @@ class Feed(UUIDAsIDModel):
|
||||
choices=LICENSE_CHOICES,
|
||||
default=2,
|
||||
)
|
||||
|
||||
image_title = models.CharField(max_length=255, default='')
|
||||
image_attribution = models.CharField(max_length=255, default='')
|
||||
image_attribution_url = models.URLField(max_length=255, blank=True)
|
||||
@ -47,6 +49,19 @@ class Feed(UUIDAsIDModel):
|
||||
def image_license_url(self):
|
||||
return(get_license_info(self.image_license))[1]
|
||||
|
||||
def __str__(self):
|
||||
return str(self.title)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
self.slug = slugify(rand_slug() + "-" + self.title)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class Feed(EpisodeAndFeed):
|
||||
author_url = models.URLField(max_length=255, default='')
|
||||
ebook_title = models.CharField(max_length=255, default='')
|
||||
ebook_url = models.URLField(max_length=255, default='')
|
||||
@ -68,57 +83,13 @@ class Feed(UUIDAsIDModel):
|
||||
def license_url(self):
|
||||
return(get_license_info(self.license))[1]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
self.slug = slugify(rand_slug() + "-" + self.title)
|
||||
super(Feed, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.title)
|
||||
|
||||
|
||||
class Episode(UUIDAsIDModel):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
class Episode(EpisodeAndFeed):
|
||||
feed = models.ForeignKey(Feed, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=255)
|
||||
author = models.CharField(max_length=255)
|
||||
slug = models.SlugField(max_length=255, unique=True)
|
||||
description = models.TextField(null=False)
|
||||
created_on = models.DateTimeField(auto_now_add=True)
|
||||
pub_date = models.DateField()
|
||||
episode_number = models.IntegerField(null=True)
|
||||
image = models.ImageField(
|
||||
storage=PublicImageStorage(),
|
||||
upload_to=slugify_file_name,
|
||||
null=True, blank=True)
|
||||
|
||||
image_license = models.SmallIntegerField(
|
||||
choices=LICENSE_CHOICES,
|
||||
default=2,
|
||||
)
|
||||
image_title = models.CharField(max_length=255, default='')
|
||||
image_attribution = models.CharField(max_length=255, default='')
|
||||
image_attribution_url = models.URLField(max_length=255, blank=True)
|
||||
original_image_url = models.URLField(max_length=255, default='')
|
||||
image_license_jurisdiction = models.TextField(null=False, default='(no jurisdiction specified)')
|
||||
|
||||
@property
|
||||
def image_license_name(self):
|
||||
return(get_license_info(self.image_license))[0]
|
||||
|
||||
@property
|
||||
def image_license_url(self):
|
||||
return(get_license_info(self.image_license))[1]
|
||||
|
||||
mp3 = models.FileField(
|
||||
storage=PublicMP3Storage(),
|
||||
upload_to=slugify_file_name,
|
||||
null=True, blank=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
self.slug = slugify(rand_slug() + "-" + self.title)
|
||||
super(Episode, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.title)
|
||||
|
Loading…
Reference in New Issue
Block a user