Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks up AbstractMedia #238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. this is not quite there as AbstractMediaBase defines search_fields and admin_form_fields that depend on fields that are now on AbstractMediaFieldAdditions

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
Loading