diff --git a/src/wagtailmedia/models.py b/src/wagtailmedia/models.py index d6cdbb9..9e2f032 100644 --- a/src/wagtailmedia/models.py +++ b/src/wagtailmedia/models.py @@ -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 ) @@ -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 + [ @@ -155,6 +159,12 @@ class Meta: verbose_name = _("media") +class AbstractMedia(AbstractMediaBase, AbstractMediaFieldAdditions): + class Meta: + abstract = True + verbose_name = _("media") + + class Media(AbstractMedia): pass