Skip to content

Commit

Permalink
Add not_page_revisions method to RevisionQuerySet and RevisionsManager
Browse files Browse the repository at this point in the history
Also simplify RevisionsManager definition using Manager.from_queryset()
  • Loading branch information
laymonage committed Jul 14, 2023
1 parent 2a888bc commit 8074ed4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions wagtail/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,8 +2656,14 @@ class Meta:


class RevisionQuerySet(models.QuerySet):
def page_revisions_q(self):
return Q(base_content_type=get_default_page_content_type())

def page_revisions(self):
return self.filter(base_content_type=get_default_page_content_type())
return self.filter(self.page_revisions_q())

def not_page_revisions(self):
return self.exclude(self.page_revisions_q())

def submitted(self):
return self.filter(submitted_for_moderation=True)
Expand All @@ -2671,12 +2677,7 @@ def for_instance(self, instance):
)


class RevisionsManager(models.Manager):
def get_queryset(self):
return RevisionQuerySet(self.model, using=self._db)

def for_instance(self, instance):
return self.get_queryset().for_instance(instance)
RevisionsManager = models.Manager.from_queryset(RevisionQuerySet)


class PageRevisionsManager(RevisionsManager):
Expand Down

0 comments on commit 8074ed4

Please sign in to comment.