Refonte de la base:
* utilisation de classes abstraites Django : Item et Collection * héritage de ces classes pour Game et Console * création d'un objet Timeline contenant le changement d'état des jeux * affichage de la Timeline sur l'interface Admin
This commit is contained in:
@ -1,53 +1,51 @@
|
||||
from core.models import Collection, Item, Timeline as BaseTimeline
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
class Console(models.Model):
|
||||
class Console(Collection):
|
||||
"""
|
||||
All console, system or box that can be used to play video games.
|
||||
"""
|
||||
name = models.CharField(max_length=254)
|
||||
|
||||
def __str__(self):
|
||||
return '%s' % self.name
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
|
||||
|
||||
class Game(models.Model):
|
||||
class Game(Item):
|
||||
"""
|
||||
A video game you will use on a specific Console.
|
||||
"""
|
||||
# class config
|
||||
TARGET_MODEL = 'games.Console'
|
||||
TARGET_VERBOSE_NAME = _('console')
|
||||
RELATED_TARGET_NAME = 'games'
|
||||
|
||||
# Status choices
|
||||
BEATEN = 0
|
||||
COMPLETED = 1
|
||||
EXCLUDED = 2
|
||||
MASTERED = 3
|
||||
UNFINISHED = 4
|
||||
BEATEN = 'beaten'
|
||||
COMPLETED = 'completed'
|
||||
EXCLUDED = 'excluded'
|
||||
MASTERED = 'mastered'
|
||||
UNFINISHED = 'unfinished'
|
||||
|
||||
STATUS_CHOICES = (
|
||||
(UNFINISHED, _('Unfinished')),
|
||||
(BEATEN, _('Beaten')),
|
||||
(COMPLETED, _('Completed')),
|
||||
(EXCLUDED, _('Excluded')),
|
||||
(MASTERED, _('Mastered')),
|
||||
(UNFINISHED, _('Unfinished')),
|
||||
)
|
||||
|
||||
# required
|
||||
name = models.CharField(max_length=254)
|
||||
console = models.ForeignKey('games.Console')
|
||||
status = models.IntegerField(
|
||||
choices=STATUS_CHOICES,
|
||||
default=UNFINISHED)
|
||||
DEFAULT_CHOICE = UNFINISHED
|
||||
|
||||
# others
|
||||
playing = models.BooleanField(default=False)
|
||||
unplayed = models.BooleanField(default=False)
|
||||
wish = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return '%s' % self.name
|
||||
|
||||
class Meta:
|
||||
ordering = ('-playing', 'name')
|
||||
|
||||
|
||||
class Timeline(BaseTimeline):
|
||||
TARGET_MODEL = 'games.Game'
|
||||
STATUS_CHOICES = Game.STATUS_CHOICES
|
||||
DEFAULT_CHOICE = Item.DEFAULT_CHOICE
|
||||
|
Reference in New Issue
Block a user