diff --git a/src/wishlist/migrations/0003_wishlist_slug_unique.py b/src/wishlist/migrations/0003_wishlist_slug_unique.py new file mode 100644 index 00000000..6611b221 --- /dev/null +++ b/src/wishlist/migrations/0003_wishlist_slug_unique.py @@ -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, + ), + ), + ] diff --git a/src/wishlist/models.py b/src/wishlist/models.py index 6c468376..0403e01e 100644 --- a/src/wishlist/models.py +++ b/src/wishlist/models.py @@ -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,}, + ) diff --git a/src/wishlist/views.py b/src/wishlist/views.py index 00246dc1..ee85c0b6 100644 --- a/src/wishlist/views.py +++ b/src/wishlist/views.py @@ -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