2017-08-22 19:02:43 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
|
|
|
|
class Collection(models.Model):
|
2017-08-24 20:36:55 +00:00
|
|
|
name = models.CharField(max_length=255, verbose_name=_('name'))
|
2017-08-22 19:02:43 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
ordering = ['name']
|
|
|
|
|
|
|
|
|
|
|
|
class Item(models.Model):
|
|
|
|
TARGET_MODEL = None
|
|
|
|
TARGET_VERBOSE_NAME = None
|
|
|
|
|
|
|
|
# status choices
|
|
|
|
CREATED = 'created'
|
|
|
|
STATUS_CHOICES = (
|
|
|
|
(CREATED, _('New')),
|
|
|
|
)
|
|
|
|
DEFAULT_CHOICE = CREATED
|
|
|
|
|
2017-08-24 20:36:55 +00:00
|
|
|
name = models.CharField(max_length=255, verbose_name=_('name'))
|
2017-08-22 19:02:43 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.name
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def on_class_prepared(cls):
|
|
|
|
"""
|
|
|
|
Add new field 'collection' which is a link to TARGET_MODEL.
|
|
|
|
Add new field 'status' which is a list of choices. With CREATED.
|
|
|
|
"""
|
|
|
|
target_field = models.ForeignKey(
|
|
|
|
cls.TARGET_MODEL,
|
|
|
|
related_name=cls.RELATED_TARGET_NAME,
|
2017-08-24 20:36:55 +00:00
|
|
|
verbose_name=_(cls.TARGET_VERBOSE_NAME))
|
2017-08-22 19:02:43 +00:00
|
|
|
target_field.contribute_to_class(cls, 'collection')
|
|
|
|
status_field = models.CharField(
|
|
|
|
max_length=30,
|
|
|
|
choices=Item.STATUS_CHOICES + cls.STATUS_CHOICES,
|
2017-08-24 20:36:55 +00:00
|
|
|
default=cls.DEFAULT_CHOICE,
|
|
|
|
verbose_name=_('status'))
|
2017-08-22 19:02:43 +00:00
|
|
|
status_field.contribute_to_class(cls, 'status')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
ordering = ['name']
|
|
|
|
|
|
|
|
|
|
|
|
class Timeline(models.Model):
|
|
|
|
"""
|
|
|
|
Keep changes on collection.
|
|
|
|
For an example, a game cretion date. Or when you completed a game.
|
|
|
|
"""
|
|
|
|
TARGET_MODEL = None
|
2017-08-24 20:36:55 +00:00
|
|
|
TARGET_VERBOSE_NAME = None
|
2017-08-22 19:02:43 +00:00
|
|
|
STATUS_CHOICES = Item.STATUS_CHOICES
|
|
|
|
DEFAULT_CHOICE = Item.CREATED
|
2017-09-03 08:53:17 +00:00
|
|
|
date = models.DateField(default=datetime.now, verbose_name=_('date'))
|
2017-08-22 19:02:43 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def on_class_prepared(cls):
|
|
|
|
"""
|
|
|
|
Add new field 'item' which is a link to TARGET_MODEL
|
|
|
|
"""
|
2017-08-24 20:36:55 +00:00
|
|
|
target_field = models.ForeignKey(
|
|
|
|
cls.TARGET_MODEL,
|
|
|
|
verbose_name=_(cls.TARGET_VERBOSE_NAME))
|
2017-08-22 19:02:43 +00:00
|
|
|
target_field.contribute_to_class(cls, 'item')
|
|
|
|
status_field = models.CharField(
|
|
|
|
max_length=30,
|
|
|
|
choices=Item.STATUS_CHOICES + cls.STATUS_CHOICES,
|
2017-08-24 20:36:55 +00:00
|
|
|
default=cls.DEFAULT_CHOICE,
|
|
|
|
verbose_name=_('status'))
|
2017-08-22 19:02:43 +00:00
|
|
|
status_field.contribute_to_class(cls, 'status')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return '%s: %s - %s' % (
|
|
|
|
self.date.strftime('%Y-%m-%d'),
|
|
|
|
self.status,
|
|
|
|
self.item)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
ordering = ('-date',)
|