Skip to content

Commit

Permalink
Breaks up AbstractMedia into AbstractMediaFieldAdditions and Abstract…
Browse files Browse the repository at this point in the history
…MediaBase so that WagtailMedia may be used with Wagtail's Document model as a storage and serve backend.
  • Loading branch information
rgs258 committed Feb 29, 2024
1 parent 849e8a4 commit bcaa6a0
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/wagtailmedia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ class MediaQuerySet(SearchableQuerySetMixin, models.QuerySet):
pass


class AbstractMedia(CollectionMember, index.Indexed, models.Model):
class AbstractMediaFieldAdditions(CollectionMember, models.Model):
title = models.CharField(max_length=255, verbose_name=_("title"))
file = models.FileField(upload_to="media", verbose_name=_("file"))
created_at = models.DateTimeField(verbose_name=_("created at"), auto_now_add=True)
uploaded_by_user = models.ForeignKey(
settings.AUTH_USER_MODEL,
verbose_name=_("uploaded by user"),
null=True,
blank=True,
editable=False,
on_delete=models.SET_NULL,
)
tags = TaggableManager(help_text=None, blank=True, verbose_name=_("tags"))

class Meta:
abstract = True
verbose_name = _("media")


class AbstractMediaBase(index.Indexed, models.Model):
type = models.CharField(
choices=MediaType.choices, max_length=255, blank=False, null=False
)
Expand All @@ -50,18 +66,6 @@ class AbstractMedia(CollectionMember, index.Indexed, models.Model):
upload_to="media_thumbnails", blank=True, verbose_name=_("thumbnail")
)

created_at = models.DateTimeField(verbose_name=_("created at"), auto_now_add=True)
uploaded_by_user = models.ForeignKey(
settings.AUTH_USER_MODEL,
verbose_name=_("uploaded by user"),
null=True,
blank=True,
editable=False,
on_delete=models.SET_NULL,
)

tags = TaggableManager(help_text=None, blank=True, verbose_name=_("tags"))

objects = MediaQuerySet.as_manager()

search_fields = CollectionMember.search_fields + [
Expand Down Expand Up @@ -155,6 +159,12 @@ class Meta:
verbose_name = _("media")


class AbstractMedia(AbstractMediaBase, AbstractMediaFieldAdditions):
class Meta:
abstract = True
verbose_name = _("media")


class Media(AbstractMedia):
pass

Expand Down

0 comments on commit bcaa6a0

Please sign in to comment.