Adds book format field with choices

This commit is contained in:
Mouse Reeve 2021-05-20 18:16:35 -07:00
parent 9933b888f9
commit 6b3447761f
2 changed files with 46 additions and 1 deletions

View file

@ -0,0 +1,35 @@
# Generated by Django 3.2 on 2021-05-21 00:17
from django.db import migrations
import bookwyrm
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0075_announcement"),
]
operations = [
migrations.RenameField(
model_name="edition",
old_name="physical_format",
new_name="physical_format_detail",
),
migrations.AddField(
model_name="edition",
name="physical_format",
field=bookwyrm.models.fields.CharField(
blank=True,
choices=[
("AudiobookFormat", "Audiobookformat"),
("EBook", "Ebook"),
("GraphicNovel", "Graphicnovel"),
("Hardcover", "Hardcover"),
("Paperback", "Paperback"),
],
max_length=255,
null=True,
),
),
]

View file

@ -169,6 +169,13 @@ class Work(OrderedCollectionPageMixin, Book):
deserialize_reverse_fields = [("editions", "editions")]
# https://schema.org/BookFormatType
FormatChoices = models.TextChoices(
"FormatChoices",
"AudiobookFormat EBook GraphicNovel Hardcover Paperback",
)
class Edition(Book):
"""an edition of a book"""
@ -186,7 +193,10 @@ class Edition(Book):
max_length=255, blank=True, null=True, deduplication_field=True
)
pages = fields.IntegerField(blank=True, null=True)
physical_format = fields.CharField(max_length=255, blank=True, null=True)
physical_format = fields.CharField(
max_length=255, choices=FormatChoices.choices, null=True, blank=True
)
physical_format_detail = fields.CharField(max_length=255, blank=True, null=True)
publishers = fields.ArrayField(
models.CharField(max_length=255), blank=True, default=list
)