Skip to content

Commit

Permalink
DSRC-117: Books/shop items (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs authored Aug 21, 2024
1 parent 03a81d8 commit bfb61e7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion etna/api/tests/expected_results/author.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@
},
"is_newly_published": true
}
]
],
"shop_items": []
}
54 changes: 54 additions & 0 deletions etna/people/migrations/0012_shopitem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 5.0.8 on 2024-08-20 10:03

import django.db.models.deletion
import modelcluster.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("images", "0009_alter_customimage_custom_sensitive_image_warning"),
("people", "0011_alter_personpage_role_alter_personpage_summary"),
]

operations = [
migrations.CreateModel(
name="ShopItem",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=255)),
("url", models.URLField()),
("price", models.DecimalField(decimal_places=2, max_digits=6)),
(
"image",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
(
"page",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="shop_items",
to="people.personpage",
),
),
],
options={
"verbose_name": "Shop item",
"verbose_name_plural": "Shop items",
},
),
]
40 changes: 40 additions & 0 deletions etna/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@ def people_pages(self):
)


class ShopItem(models.Model):
"""Shop item model
This model is used to represent a shop item.
"""

page = ParentalKey(
"PersonPage",
on_delete=models.CASCADE,
related_name="shop_items",
)
title = models.CharField(max_length=255)
url = models.URLField()
price = models.DecimalField(max_digits=6, decimal_places=2)
image = models.ForeignKey(
get_image_model_string(),
on_delete=models.SET_NULL,
related_name="+",
null=True,
)

def __str__(self):
return self.title

class Meta:
verbose_name = "Shop item"
verbose_name_plural = "Shop items"

api_fields = [
APIField("title"),
APIField("url"),
APIField("price"),
APIField("image", serializer=ImageSerializer(rendition_size="fill-600x400")),
]


class PersonPage(BasePage):
"""Person page
Expand Down Expand Up @@ -88,6 +124,7 @@ class PersonPage(BasePage):
FieldPanel("role"),
FieldPanel("summary"),
FieldPanel("research_summary"),
InlinePanel("shop_items", label="Shop items"),
]

promote_panels = [
Expand Down Expand Up @@ -138,6 +175,9 @@ class Meta:
required_api_fields=["teaser_image"], many=True
),
),
APIField(
"shop_items",
),
]

@cached_property
Expand Down

0 comments on commit bfb61e7

Please sign in to comment.