Set book availability

This commit is contained in:
Mouse Reeve 2022-01-17 09:21:58 -08:00
parent 7b1693a435
commit 39814a21f2
5 changed files with 51 additions and 26 deletions

View file

@ -225,7 +225,7 @@ class LinkDomainForm(CustomForm):
class FileLinkForm(CustomForm):
class Meta:
model = models.FileLink
fields = ["url", "filetype", "book", "added_by"]
fields = ["url", "filetype", "availability", "book", "added_by"]
class EditionForm(CustomForm):

View file

@ -1,24 +0,0 @@
# Generated by Django 3.2.10 on 2022-01-17 17:03
import bookwyrm.models.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookwyrm', '0128_merge_0126_auto_20220112_2315_0127_auto_20220110_2211'),
]
operations = [
migrations.AddField(
model_name='filelink',
name='is_purchase',
field=bookwyrm.models.fields.BooleanField(blank=True, null=True),
),
migrations.AlterField(
model_name='filelink',
name='filetype',
field=bookwyrm.models.fields.CharField(max_length=50),
),
]

View file

@ -0,0 +1,32 @@
# Generated by Django 3.2.10 on 2022-01-17 17:16
import bookwyrm.models.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0128_merge_0126_auto_20220112_2315_0127_auto_20220110_2211"),
]
operations = [
migrations.AddField(
model_name="filelink",
name="availability",
field=bookwyrm.models.fields.CharField(
choices=[
("free", "Free"),
("purchase", "Purchasable"),
("loan", "Available for loan"),
],
default="free",
max_length=100,
),
),
migrations.AlterField(
model_name="filelink",
name="filetype",
field=bookwyrm.models.fields.CharField(max_length=50),
),
]

View file

@ -47,6 +47,13 @@ class Link(ActivitypubMixin, BookWyrmModel):
return super().save(*args, **kwargs)
AvailabilityChoices = [
("free", _("Free")),
("purchase", _("Purchasable")),
("loan", _("Available for loan")),
]
class FileLink(Link):
"""a link to a file"""
@ -54,7 +61,9 @@ class FileLink(Link):
"Book", on_delete=models.CASCADE, related_name="file_links", null=True
)
filetype = fields.CharField(max_length=50, activitypub_field="mediaType")
is_purchase = fields.BooleanField(null=True, blank=True)
availability = fields.CharField(
max_length=100, choices=AvailabilityChoices, default="free"
)
StatusChoices = [

View file

@ -43,6 +43,14 @@
{% include 'snippets/form_errors.html' with errors_list=file_link_form.filetype.errors id="desc_filetype" %}
</div>
</div>
<div>
<label class="label" for="id_availability">
{% trans "Availability:" %}
</label>
<div class="select">
{{ file_link_form.availability }}
</div>
</div>
{% endblock %}