hide fulfilled wishes from the list, while here set verbose_plural_name and make slug unique in the db.

This commit is contained in:
Thomas Steen Rasmussen 2020-05-09 14:24:15 +02:00
parent 57dce1f887
commit 57cf6eaf56
3 changed files with 41 additions and 14 deletions

View file

@ -0,0 +1,25 @@
# Generated by Django 3.0.3 on 2020-05-09 12:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wishlist", "0002_auto_20200219_2008"),
]
operations = [
migrations.AlterModelOptions(
name="wish", options={"verbose_name_plural": "wishes"},
),
migrations.AlterField(
model_name="wish",
name="slug",
field=models.SlugField(
blank=True,
help_text="The url slug for this wish. Leave blank to autogenerate one.",
unique=True,
),
),
]

View file

@ -1,8 +1,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
from django.core.exceptions import ValidationError
from utils.models import CampRelatedModel
@ -11,13 +10,15 @@ class Wish(CampRelatedModel):
This model contains the stuff BornHack needs. This can be anything from kitchen equipment
to network cables, or anything really.
"""
name = models.CharField(
max_length=100,
help_text="Short description of the wish",
)
class Meta:
verbose_name_plural = "wishes"
name = models.CharField(max_length=100, help_text="Short description of the wish",)
slug = models.SlugField(
blank=True,
unique=True,
help_text="The url slug for this wish. Leave blank to autogenerate one.",
)
@ -25,10 +26,7 @@ class Wish(CampRelatedModel):
help_text="Description of the needed item. Markdown is supported!"
)
count = models.IntegerField(
default=1,
help_text="How many do we need?",
)
count = models.IntegerField(default=1, help_text="How many do we need?",)
fulfilled = models.BooleanField(
default=False,
@ -59,7 +57,7 @@ class Wish(CampRelatedModel):
super().save(**kwargs)
def get_absolute_url(self):
return reverse("wishlist:detail", kwargs={
"camp_slug": self.camp.slug,
"wish_slug": self.slug,
})
return reverse(
"wishlist:detail",
kwargs={"camp_slug": self.camp.slug, "wish_slug": self.slug,},
)

View file

@ -7,6 +7,10 @@ class WishListView(ListView):
model = Wish
template_name = "wish_list.html"
def get_queryset(self, **kwargs):
# only show unfulfilled wishes
return super().get_queryset().filter(fulfilled=False)
class WishDetailView(DetailView):
model = Wish