Game - ajout de propriétés pour :

* le fait d'avoir joué ou non au jeu
  * de le vouloir dans sa liste de souhaits
  * de donner l'état de progression dans le jeu parmi :
    * inachevé
    * globalement terminé
    * complètement terminé
    * maîtrisé
This commit is contained in:
Olivier DOSSMANN 2017-08-17 22:42:48 +02:00
parent acbe2ba582
commit 5cbef15a13
5 changed files with 75 additions and 2 deletions

5
TODO
View File

@ -3,8 +3,11 @@
* Gérer les figurines (trouver le nom de l'objet qui permet de les regrouper, par exemple Skylanders, Disney Infinity, etc.)
* Tests sur Console
* Tests sur Game
* Ajouter des attributs à Game
* Données initiales des consoles connues
* Dockerfile avec UWSGI
* API django rest framework
* documentation API
* travis.yml to launch tests
# Idée

View File

@ -2,5 +2,14 @@ from django.contrib import admin
from games.models import Console, Game
class GameAdmin(admin.ModelAdmin):
list_display = (
'name', 'playing', 'status', 'wish')
list_filter = [
'status',
'playing',
'wish']
search_fields = ('name',)
admin.site.register(Console)
admin.site.register(Game)
admin.site.register(Game, GameAdmin)

View File

@ -28,6 +28,11 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=254)),
('console', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='games.Console')),
('playing', models.BooleanField(default=False)),
('status', models.IntegerField(choices=[(4, 'Unfinished'), (0, 'Beaten'), (1, 'Completed'), (2, 'Excluded'), (3, 'Mastered')], default=4)),
('unplayed', models.BooleanField(default=False)),
('wish', models.BooleanField(default=False)),
],
options={'ordering': ('-playing', 'name')},
),
]

View File

@ -1,4 +1,5 @@
from django.db import models
from django.utils.translation import ugettext as _
class Console(models.Model):
@ -18,8 +19,35 @@ class Game(models.Model):
"""
A video game you will use on a specific Console.
"""
# Status choices
BEATEN = 0
COMPLETED = 1
EXCLUDED = 2
MASTERED = 3
UNFINISHED = 4
STATUS_CHOICES = (
(UNFINISHED, _('Unfinished')),
(BEATEN, _('Beaten')),
(COMPLETED, _('Completed')),
(EXCLUDED, _('Excluded')),
(MASTERED, _('Mastered')),
)
# required
name = models.CharField(max_length=254)
console = models.ForeignKey('games.Console')
status = models.IntegerField(
choices=STATUS_CHOICES,
default=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')

View File

@ -0,0 +1,28 @@
from django.test import TestCase
from games.models import Console, Game
class GameTest(TestCase):
"""
Game Model
"""
def setUp(self):
self.console = Console.objects.create(name='BestConsole4Ever')
Game.objects.create(
name='Deponia', playing=False, console=self.console)
Game.objects.create(
name='Aladdin', playing=True, console=self.console)
Game.objects.create(
name='Persona 5', playing=True, console=self.console)
def test_game_are_sorted_by_playing_and_name(self):
"""
Games should be sorted by playing state (playing should be True first)
then by name in alphabetical order.
"""
games = list(Game.objects.all().values_list('name', flat=True))
sorted_games = list(Game.objects.all().order_by(
'-playing', 'name').values_list('name', flat=True))
self.assertEqual(games, sorted_games)