Nouvelle collection : les figurines
This commit is contained in:
0
collection/figurines/__init__.py
Normal file
0
collection/figurines/__init__.py
Normal file
17
collection/figurines/admin.py
Normal file
17
collection/figurines/admin.py
Normal file
@ -0,0 +1,17 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import ugettext as _
|
||||
from figurines.models import Set, Figurine
|
||||
|
||||
|
||||
class FigurineInline(admin.TabularInline):
|
||||
model = Figurine
|
||||
fields = ('name', 'wish')
|
||||
extra = 2
|
||||
|
||||
|
||||
class SetAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
inlines = (FigurineInline,)
|
||||
|
||||
|
||||
admin.site.register(Set, SetAdmin)
|
5
collection/figurines/apps.py
Normal file
5
collection/figurines/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class FigurinesConfig(AppConfig):
|
||||
name = 'figurines'
|
16
collection/figurines/fixtures/initial.yaml
Normal file
16
collection/figurines/fixtures/initial.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
- model: figurines.set
|
||||
pk: 1
|
||||
fields:
|
||||
name: Amiibo
|
||||
- model: figurines.set
|
||||
pk: 2
|
||||
fields:
|
||||
name: Disney Infinity
|
||||
- model: figurines.set
|
||||
pk: 3
|
||||
fields:
|
||||
name: Lego Dimensions
|
||||
- model: figurines.set
|
||||
pk: 4
|
||||
fields:
|
||||
name: Skylanders
|
43
collection/figurines/migrations/0001_initial.py
Normal file
43
collection/figurines/migrations/0001_initial.py
Normal file
@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.5 on 2017-09-18 19:11
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Figurine',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(help_text='Figurine denomination', max_length=255, verbose_name='nom')),
|
||||
('wish', models.BooleanField(default=False, help_text='You need this figurine.', verbose_name='wish?')),
|
||||
('status', models.CharField(choices=[('created', 'New'), ('created', 'New')], default='created', help_text='Figurine progression', max_length=30, verbose_name='status')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Set',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(help_text='Usual name of figurines set.', max_length=255, verbose_name='nom')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'set',
|
||||
'verbose_name_plural': 'sets',
|
||||
'ordering': ('name',),
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='figurine',
|
||||
name='collection',
|
||||
field=models.ForeignKey(help_text='Becoming set', on_delete=django.db.models.deletion.CASCADE, related_name='figurines', to='figurines.Set', verbose_name='set'),
|
||||
),
|
||||
]
|
0
collection/figurines/migrations/__init__.py
Normal file
0
collection/figurines/migrations/__init__.py
Normal file
46
collection/figurines/models.py
Normal file
46
collection/figurines/models.py
Normal file
@ -0,0 +1,46 @@
|
||||
from core.models import Collection, Item, Timeline
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
class Set(Collection):
|
||||
"""
|
||||
Common name used to describe a set of characters, objects or vehicles
|
||||
"""
|
||||
def __str__(self):
|
||||
return '%s' % self.name
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
verbose_name = _('set')
|
||||
verbose_name_plural = _('sets')
|
||||
|
||||
# Redefine help_text (for documentation, API, etc.)
|
||||
Set._meta.get_field('name').help_text = _('Usual name of figurines set.')
|
||||
|
||||
|
||||
class Figurine(Item):
|
||||
"""
|
||||
A character, a gadget, a vehicle or a world used on a Game to use specific
|
||||
levels, abilities, etc.
|
||||
"""
|
||||
# class config
|
||||
TARGET_MODEL = 'figurines.Set'
|
||||
TARGET_VERBOSE_NAME = _('set')
|
||||
RELATED_TARGET_NAME = 'figurines'
|
||||
|
||||
# No more status choices thant "CREATED"
|
||||
|
||||
wish = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name=_('wish?'),
|
||||
help_text=_('You need this figurine.'))
|
||||
|
||||
class Meta:
|
||||
ordering: ('name')
|
||||
|
||||
|
||||
# Redefine help_text (for documentation, API, etc.)
|
||||
Figurine._meta.get_field('name').help_text = _('Figurine denomination')
|
||||
Figurine._meta.get_field('collection').help_text = _('Becoming set')
|
||||
Figurine._meta.get_field('status').help_text = _('Figurine progression')
|
0
collection/figurines/tests/__init__.py
Normal file
0
collection/figurines/tests/__init__.py
Normal file
17
collection/figurines/tests/test_set.py
Normal file
17
collection/figurines/tests/test_set.py
Normal file
@ -0,0 +1,17 @@
|
||||
from django.test import TestCase
|
||||
from figurines.models import Set
|
||||
|
||||
|
||||
class SetTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
Set.objects.create(name='DimDim')
|
||||
Set.objects.create(name='Rainbow')
|
||||
Set.objects.create(name='Mystery')
|
||||
|
||||
|
||||
def test_sorted_sets(self):
|
||||
sets = list(Set.objects.all().values_list('name', flat=True))
|
||||
sorted_sets = list(
|
||||
Set.objects.all().order_by('name').values_list('name', flat=True))
|
||||
self.assertEqual(sets, sorted_sets)
|
Reference in New Issue
Block a user