Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSRC-117: Books/shop items #1709

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading