2
0
Эх сурвалжийг харах

Fix live preview for BlogPage and RecipePage authors (#397)

sag᠎e 2 жил өмнө
parent
commit
811507f6d4

+ 7 - 2
bakerydemo/blog/models.py

@@ -13,7 +13,6 @@ from wagtail.models import Orderable, Page
 from wagtail.search import index
 
 from bakerydemo.base.blocks import BaseStreamBlock
-from bakerydemo.base.models import Person
 
 
 class BlogPersonRelationship(Orderable, models.Model):
@@ -99,7 +98,13 @@ class BlogPage(Page):
         with a loop on the template. If we tried to access the blog_person_
         relationship directly we'd print `blog.BlogPersonRelationship.None`
         """
-        return Person.objects.filter(live=True, person_blog_relationship__page=self)
+        # Only return authors that are not in draft
+        return [
+            n.person
+            for n in self.blog_person_relationship.filter(
+                person__live=True
+            ).select_related("person")
+        ]
 
     @property
     def get_tags(self):

+ 11 - 6
bakerydemo/recipes/models.py

@@ -6,7 +6,6 @@ from wagtail.models import Orderable, Page
 from wagtail.search import index
 
 from bakerydemo.base.blocks import BaseStreamBlock
-from bakerydemo.base.models import Person
 
 from .blocks import RecipeStreamBlock
 
@@ -104,13 +103,19 @@ class RecipePage(Page):
 
     def authors(self):
         """
-        Returns the BlogPage's related people. Again note that we are using
-        the ParentalKey's related_name from the BlogPersonRelationship model
+        Returns the RecipePage's related people. Again note that we are using
+        the ParentalKey's related_name from the RecipePersonRelationship model
         to access these objects. This allows us to access the Person objects
-        with a loop on the template. If we tried to access the blog_person_
-        relationship directly we'd print `blog.BlogPersonRelationship.None`
+        with a loop on the template. If we tried to access the recipe_person_
+        relationship directly we'd print `recipe.RecipePersonRelationship.None`
         """
-        return Person.objects.filter(live=True, person_recipe_relationship__page=self)
+        # Only return authors that are not in draft
+        return [
+            n.person
+            for n in self.recipe_person_relationship.filter(
+                person__live=True
+            ).select_related("person")
+        ]
 
     # Specifies parent to Recipe as being RecipeIndexPages
     parent_page_types = ["RecipeIndexPage"]