2020-05-09 12:24:15 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2020-02-13 21:07:28 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.text import slugify
|
|
|
|
from utils.models import CampRelatedModel
|
|
|
|
|
|
|
|
|
|
|
|
class Wish(CampRelatedModel):
|
|
|
|
"""
|
|
|
|
This model contains the stuff BornHack needs. This can be anything from kitchen equipment
|
|
|
|
to network cables, or anything really.
|
|
|
|
"""
|
2020-05-09 12:24:15 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = "wishes"
|
|
|
|
|
|
|
|
name = models.CharField(max_length=100, help_text="Short description of the wish",)
|
2020-02-13 21:07:28 +00:00
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
blank=True,
|
2020-05-09 12:24:15 +00:00
|
|
|
unique=True,
|
2020-02-13 21:07:28 +00:00
|
|
|
help_text="The url slug for this wish. Leave blank to autogenerate one.",
|
|
|
|
)
|
|
|
|
|
|
|
|
description = models.TextField(
|
|
|
|
help_text="Description of the needed item. Markdown is supported!"
|
|
|
|
)
|
|
|
|
|
2020-05-09 12:24:15 +00:00
|
|
|
count = models.IntegerField(default=1, help_text="How many do we need?",)
|
2020-02-13 21:07:28 +00:00
|
|
|
|
|
|
|
fulfilled = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text="A Wish is marked as fulfilled when we no longer need the thing.",
|
|
|
|
)
|
|
|
|
|
|
|
|
team = models.ForeignKey(
|
|
|
|
"teams.Team",
|
|
|
|
help_text="The team that needs this thing. When in doubt pick Orga :)",
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name="wishes",
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def camp(self):
|
|
|
|
return self.team.camp
|
|
|
|
|
|
|
|
camp_filter = "team__camp"
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def save(self, **kwargs):
|
|
|
|
if not self.slug:
|
|
|
|
self.slug = slugify(self.name)
|
|
|
|
if not self.slug:
|
|
|
|
raise ValidationError("Unable to slugify")
|
|
|
|
super().save(**kwargs)
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2020-05-09 12:24:15 +00:00
|
|
|
return reverse(
|
|
|
|
"wishlist:detail",
|
|
|
|
kwargs={"camp_slug": self.camp.slug, "wish_slug": self.slug,},
|
|
|
|
)
|