kopia lustrzana https://github.com/wagtail/bakerydemo
Rename People model to Person (#342)
rodzic
8c38696092
commit
172cdd9e5f
|
@ -1,6 +1,6 @@
|
|||
[
|
||||
{
|
||||
"model": "base.people",
|
||||
"model": "base.person",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"first_name": "Roberta",
|
||||
|
@ -10,7 +10,7 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"model": "base.people",
|
||||
"model": "base.person",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"first_name": "Olivia",
|
||||
|
@ -20,7 +20,7 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"model": "base.people",
|
||||
"model": "base.person",
|
||||
"pk": 3,
|
||||
"fields": {
|
||||
"first_name": "Lightnin'",
|
||||
|
@ -30,7 +30,7 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"model": "base.people",
|
||||
"model": "base.person",
|
||||
"pk": 4,
|
||||
"fields": {
|
||||
"first_name": "Muddy",
|
||||
|
@ -122,75 +122,75 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"sort_order": 0,
|
||||
"page": 62,
|
||||
"people": 1
|
||||
"person": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 3,
|
||||
"fields": {
|
||||
"sort_order": 0,
|
||||
"page": 68,
|
||||
"people": 2
|
||||
"person": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 4,
|
||||
"fields": {
|
||||
"sort_order": 0,
|
||||
"page": 72,
|
||||
"people": 3
|
||||
"person": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 5,
|
||||
"fields": {
|
||||
"sort_order": 0,
|
||||
"page": 73,
|
||||
"people": 3
|
||||
"person": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 6,
|
||||
"fields": {
|
||||
"sort_order": 0,
|
||||
"page": 74,
|
||||
"people": 1
|
||||
"person": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 7,
|
||||
"fields": {
|
||||
"sort_order": 1,
|
||||
"page": 74,
|
||||
"people": 3
|
||||
"person": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 8,
|
||||
"fields": {
|
||||
"sort_order": 1,
|
||||
"page": 73,
|
||||
"people": 1
|
||||
"person": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "blog.blogpeoplerelationship",
|
||||
"model": "blog.blogpersonrelationship",
|
||||
"pk": 9,
|
||||
"fields": {
|
||||
"sort_order": 0,
|
||||
"page": 77,
|
||||
"people": 2
|
||||
"person": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ from wagtail.core.rich_text import RichText
|
|||
from wagtail.images.models import Image
|
||||
from willow.image import Image as WillowImage
|
||||
|
||||
from bakerydemo.base.models import FooterText, HomePage, People, StandardPage
|
||||
from bakerydemo.base.models import FooterText, HomePage, Person, StandardPage
|
||||
from bakerydemo.blog.models import BlogIndexPage, BlogPage
|
||||
from bakerydemo.breads.models import (
|
||||
BreadIngredient,
|
||||
|
@ -140,7 +140,7 @@ class Command(BaseCommand):
|
|||
|
||||
self.stdout.write("Creating people...")
|
||||
for _ in range(snippet_count):
|
||||
People.objects.create(
|
||||
Person.objects.create(
|
||||
first_name=lorem_ipsum.words(1, common=False),
|
||||
last_name=lorem_ipsum.words(1, common=False),
|
||||
job_title=lorem_ipsum.words(1, common=False),
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 3.2.15 on 2022-09-02 14:39
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("blog", "0005_use_json_field_for_body_streamfield"),
|
||||
("wagtailimages", "0024_index_image_file_hash"),
|
||||
("base", "0009_alter_homepage_promo_text"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name="People",
|
||||
new_name="Person",
|
||||
),
|
||||
]
|
|
@ -14,13 +14,13 @@ from .blocks import BaseStreamBlock
|
|||
|
||||
|
||||
@register_snippet
|
||||
class People(index.Indexed, ClusterableModel):
|
||||
class Person(index.Indexed, ClusterableModel):
|
||||
"""
|
||||
A Django model to store People objects.
|
||||
A Django model to store Person objects.
|
||||
It uses the `@register_snippet` decorator to allow it to be accessible
|
||||
via the Snippets UI (e.g. /admin/snippets/base/people/)
|
||||
via the Snippets UI (e.g. /admin/snippets/base/person/)
|
||||
|
||||
`People` uses the `ClusterableModel`, which allows the relationship with
|
||||
`Person` uses the `ClusterableModel`, which allows the relationship with
|
||||
another model to be stored locally to the 'parent' model (e.g. a PageModel)
|
||||
until the parent is explicitly saved. This allows the editor to use the
|
||||
'Preview' button, to preview the content, without saving the relationships
|
||||
|
|
|
@ -4,7 +4,7 @@ from wagtail.contrib.modeladmin.options import (
|
|||
modeladmin_register,
|
||||
)
|
||||
|
||||
from bakerydemo.base.models import FooterText, People
|
||||
from bakerydemo.base.models import FooterText, Person
|
||||
from bakerydemo.breads.models import BreadIngredient, BreadType, Country
|
||||
|
||||
"""
|
||||
|
@ -48,8 +48,8 @@ class BreadModelAdminGroup(ModelAdminGroup):
|
|||
items = (BreadIngredientAdmin, BreadTypeAdmin, BreadCountryAdmin)
|
||||
|
||||
|
||||
class PeopleModelAdmin(ModelAdmin):
|
||||
model = People
|
||||
class PersonModelAdmin(ModelAdmin):
|
||||
model = Person
|
||||
menu_label = "People" # ditch this to use verbose_name_plural from model
|
||||
menu_icon = "fa-users" # change as required
|
||||
list_display = ("first_name", "last_name", "job_title", "thumb_image")
|
||||
|
@ -67,7 +67,7 @@ class BakeryModelAdminGroup(ModelAdminGroup):
|
|||
menu_label = "Bakery Misc"
|
||||
menu_icon = "fa-cutlery" # change as required
|
||||
menu_order = 300 # will put in 4th place (000 being 1st, 100 2nd)
|
||||
items = (PeopleModelAdmin, FooterTextAdmin)
|
||||
items = (PersonModelAdmin, FooterTextAdmin)
|
||||
|
||||
|
||||
# When using a ModelAdminGroup class to group several ModelAdmin classes together,
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.15 on 2022-09-02 14:39
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("base", "0010_rename_people_person"),
|
||||
("blog", "0005_use_json_field_for_body_streamfield"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name="BlogPeopleRelationship",
|
||||
new_name="BlogPersonRelationship",
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="blogpersonrelationship",
|
||||
old_name="people",
|
||||
new_name="person",
|
||||
),
|
||||
]
|
|
@ -15,22 +15,22 @@ from wagtail.search import index
|
|||
from bakerydemo.base.blocks import BaseStreamBlock
|
||||
|
||||
|
||||
class BlogPeopleRelationship(Orderable, models.Model):
|
||||
class BlogPersonRelationship(Orderable, models.Model):
|
||||
"""
|
||||
This defines the relationship between the `People` within the `base`
|
||||
app and the BlogPage below. This allows People to be added to a BlogPage.
|
||||
This defines the relationship between the `Person` within the `base`
|
||||
app and the BlogPage below. This allows people to be added to a BlogPage.
|
||||
|
||||
We have created a two way relationship between BlogPage and People using
|
||||
We have created a two way relationship between BlogPage and Person using
|
||||
the ParentalKey and ForeignKey
|
||||
"""
|
||||
|
||||
page = ParentalKey(
|
||||
"BlogPage", related_name="blog_person_relationship", on_delete=models.CASCADE
|
||||
)
|
||||
people = models.ForeignKey(
|
||||
"base.People", related_name="person_blog_relationship", on_delete=models.CASCADE
|
||||
person = models.ForeignKey(
|
||||
"base.Person", related_name="person_blog_relationship", on_delete=models.CASCADE
|
||||
)
|
||||
panels = [FieldPanel("people")]
|
||||
panels = [FieldPanel("person")]
|
||||
|
||||
|
||||
class BlogPageTag(TaggedItemBase):
|
||||
|
@ -49,8 +49,8 @@ class BlogPage(Page):
|
|||
"""
|
||||
A Blog Page
|
||||
|
||||
We access the People object with an inline panel that references the
|
||||
ParentalKey's related_name in BlogPeopleRelationship. More docs:
|
||||
We access the Person object with an inline panel that references the
|
||||
ParentalKey's related_name in BlogPersonRelationship. More docs:
|
||||
https://docs.wagtail.org/en/stable/topics/pages.html#inline-models
|
||||
"""
|
||||
|
||||
|
@ -88,13 +88,13 @@ class BlogPage(Page):
|
|||
|
||||
def authors(self):
|
||||
"""
|
||||
Returns the BlogPage's related People. Again note that we are using
|
||||
the ParentalKey's related_name from the BlogPeopleRelationship model
|
||||
to access these objects. This allows us to access the People objects
|
||||
Returns the BlogPage's related people. Again note that we are using
|
||||
the ParentalKey's related_name from the BlogPersonRelationship 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.BlogPeopleRelationship.None`
|
||||
relationship directly we'd print `blog.BlogPersonRelationship.None`
|
||||
"""
|
||||
authors = [n.people for n in self.blog_person_relationship.all()]
|
||||
authors = [n.person for n in self.blog_person_relationship.all()]
|
||||
|
||||
return authors
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class OperatingHours(models.Model):
|
|||
class LocationOperatingHours(Orderable, OperatingHours):
|
||||
"""
|
||||
A model creating a relationship between the OperatingHours and Location
|
||||
Note that unlike BlogPeopleRelationship we don't include a ForeignKey to
|
||||
Note that unlike BlogPersonRelationship we don't include a ForeignKey to
|
||||
OperatingHours as we don't need that relationship (e.g. any Location open
|
||||
a certain day of the week). The ParentalKey is the minimum required to
|
||||
relate the two objects to one another. We use the ParentalKey's related_
|
||||
|
|
Ładowanie…
Reference in New Issue