You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wish/wishlist/models.py

43 lines
2.0 KiB
Python

from django.db import models
from django.conf import settings
class WishList(models.Model):
# Meta class?
slug = models.SlugField(max_length=50, blank=False, primary_key=True, help_text="URL suffix for this wishlist. Must not clash existing ones, nor be 'user' nor 'item'.")
name = models.TextField(help_text="The title of the wishlist.")
description = models.TextField(blank=True, help_text="Optional (public) description of the wishlist.")
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, help_text="The user owning this wishlist.")
hidden = models.BooleanField(default=True, help_text="Whether to hide on the users' list of their wishlists.")
hide_granted = models.BooleanField(default=False, help_text="Whether to hide already fulfilled wishes.")
def __str__(self): return self.name
def get_absolute_url(self):
from django.urls import reverse
return reverse('wishlist', kwargs={'slug':self.slug})
class WishedItem(models.Model):
# Meta class?
id = models.AutoField(primary_key=True)
name = models.TextField(help_text="Name of the wished item.")
description = models.TextField(blank=True, help_text="Detailed description of the item, for example its specification.")
wishlists = models.ManyToManyField(WishList, related_name='wishes', help_text="Wishlists that this wish should be part of.")
def __str__(self): return self.name
def get_absolute_url(self):
from django.urls import reverse
return reverse('wished_item', kwargs={'pk': self.id})
# FIXME: create more sensible name...
class DreamComeTrue(models.Model):
id = models.AutoField(primary_key=True)
item = models.ForeignKey(WishedItem, on_delete=models.CASCADE, help_text="What wish has been fulfilled.")
when = models.DateTimeField(auto_now_add=True, help_text="When the dream came true")
note = models.TextField(blank=True, help_text="Optional note, e.g. tracking number. Private, shown only to owner.")
def __str__(self): return f"Dream of {self.item} came true on {self.when}"