Skip to content

Commit

Permalink
Add text-based URL field, change columns to text
Browse files Browse the repository at this point in the history
  • Loading branch information
AetherUnbound committed May 10, 2024
1 parent 0c39a99 commit 9f69c08
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
3 changes: 1 addition & 2 deletions api/api/models/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ class Audio(AudioFileMixin, AbstractMedia):
)

# Replaces the foreign key to AudioSet
audio_set_foreign_identifier = models.CharField(
max_length=1000,
audio_set_foreign_identifier = models.TextField(
blank=True,
null=True,
help_text="Reference to set of which this track is a part.",
Expand Down
21 changes: 21 additions & 0 deletions api/api/models/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django import forms
from django.core import validators
from django.db import models
from django.utils.translation import gettext_lazy as _


class URLTextField(models.TextField):
"""URL field which uses the underlying Postgres TEXT column type."""

default_validators = [validators.URLValidator()]
description = _("URL")

def formfield(self, **kwargs):
# As with CharField, this will cause URL validation to be performed
# twice.
return super().formfield(
**{
"form_class": forms.URLField,
**kwargs,
}
)
35 changes: 16 additions & 19 deletions api/api/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django.db import models

from api.models import fields


class IdentifierMixin(models.Model):
"""
Expand Down Expand Up @@ -32,11 +34,10 @@ class ForeignIdentifierMixin(models.Model):
This mixin adds
- foreign_identifier: CharField
- foreign_identifier: TextField
"""

foreign_identifier = models.CharField(
max_length=1000,
foreign_identifier = models.TextField(
blank=True,
null=True,
db_index=True,
Expand All @@ -55,34 +56,31 @@ class MediaMixin(models.Model):
The mixin adds
- title: CharField
- foreign_landing_url: CharField
- creator: CharField
- creator_url: CharField
- thumbnail: URLField
- title: TextField
- foreign_landing_url: URLTextField
- creator: TextField
- creator_url: URLTextField
- thumbnail: URLTextField
- provider: CharField
"""

title = models.CharField(
max_length=2000,
title = models.TextField(
blank=True,
null=True,
help_text="The name of the media.",
)
foreign_landing_url = models.CharField(
max_length=1000,
foreign_landing_url = fields.URLTextField(
blank=True,
null=True,
help_text="The landing page of the work.",
)

creator = models.CharField(
max_length=2000,
creator = models.TextField(
blank=True,
null=True,
help_text="The name of the media creator.",
)
creator_url = models.URLField(
creator_url = fields.URLTextField(
max_length=2000,
blank=True,
null=True,
Expand All @@ -92,8 +90,7 @@ class MediaMixin(models.Model):
# Because all forms of media have a thumbnail for visual representation
# For images, this field is not used as images are generated using Photon.
# For audio, this field points to the artwork, or is ``null``.
thumbnail = models.URLField(
max_length=1000,
thumbnail = fields.URLTextField(
blank=True,
null=True,
help_text="The thumbnail for the media.",
Expand All @@ -120,12 +117,12 @@ class FileMixin(models.Model):
This mixin adds
- url: URLField
- url: URLTextField
- filesize: IntegerField
- filetype: CharField
"""

url = models.URLField(
url = fields.URLTextField(
unique=True,
max_length=1000,
help_text="The actual URL to the media file.",
Expand Down

0 comments on commit 9f69c08

Please sign in to comment.