浏览代码

Add GenericRelation to revisions and workflow states

Sage Abdullah 1 年之前
父节点
当前提交
549400c645
共有 2 个文件被更改,包括 42 次插入0 次删除
  1. 25 0
      bakerydemo/base/models.py
  2. 17 0
      bakerydemo/breads/models.py

+ 25 - 0
bakerydemo/base/models.py

@@ -1,5 +1,6 @@
 from __future__ import unicode_literals
 from __future__ import unicode_literals
 
 
+from django.contrib.contenttypes.fields import GenericRelation
 from django.db import models
 from django.db import models
 from django.utils.translation import gettext as _
 from django.utils.translation import gettext as _
 from modelcluster.fields import ParentalKey
 from modelcluster.fields import ParentalKey
@@ -67,6 +68,22 @@ class Person(
         related_name="+",
         related_name="+",
     )
     )
 
 
+    workflow_states = GenericRelation(
+        "wagtailcore.WorkflowState",
+        content_type_field="base_content_type",
+        object_id_field="object_id",
+        related_query_name="person",
+        for_concrete_model=False,
+    )
+
+    revisions = GenericRelation(
+        "wagtailcore.Revision",
+        content_type_field="base_content_type",
+        object_id_field="object_id",
+        related_query_name="person",
+        for_concrete_model=False,
+    )
+
     panels = [
     panels = [
         MultiFieldPanel(
         MultiFieldPanel(
             [
             [
@@ -163,6 +180,14 @@ class FooterText(
 
 
     body = RichTextField()
     body = RichTextField()
 
 
+    revisions = GenericRelation(
+        "wagtailcore.Revision",
+        content_type_field="base_content_type",
+        object_id_field="object_id",
+        related_query_name="footer_text",
+        for_concrete_model=False,
+    )
+
     panels = [
     panels = [
         FieldPanel("body"),
         FieldPanel("body"),
         PublishingPanel(),
         PublishingPanel(),

+ 17 - 0
bakerydemo/breads/models.py

@@ -1,4 +1,5 @@
 from django import forms
 from django import forms
+from django.contrib.contenttypes.fields import GenericRelation
 from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 from django.db import models
 from django.db import models
 from modelcluster.fields import ParentalManyToManyField
 from modelcluster.fields import ParentalManyToManyField
@@ -42,6 +43,14 @@ class BreadIngredient(DraftStateMixin, RevisionMixin, models.Model):
 
 
     name = models.CharField(max_length=255)
     name = models.CharField(max_length=255)
 
 
+    revisions = GenericRelation(
+        "wagtailcore.Revision",
+        content_type_field="base_content_type",
+        object_id_field="object_id",
+        related_query_name="bread_ingredient",
+        for_concrete_model=False,
+    )
+
     panels = [
     panels = [
         FieldPanel("name"),
         FieldPanel("name"),
     ]
     ]
@@ -66,6 +75,14 @@ class BreadType(RevisionMixin, models.Model):
 
 
     title = models.CharField(max_length=255)
     title = models.CharField(max_length=255)
 
 
+    revisions = GenericRelation(
+        "wagtailcore.Revision",
+        content_type_field="base_content_type",
+        object_id_field="object_id",
+        related_query_name="bread_type",
+        for_concrete_model=False,
+    )
+
     panels = [
     panels = [
         FieldPanel("title"),
         FieldPanel("title"),
     ]
     ]