Migrated to AmiiboFigure and AmiiboCard models
This commit is contained in:
parent
23c3405a00
commit
a4795c2b4a
|
@ -12,6 +12,7 @@ import reversion
|
|||
# amiibo
|
||||
from .models import (
|
||||
Collection, Amiibo,
|
||||
AmiiboFigure, AmiiboCard,
|
||||
AmiiboShop,
|
||||
AmiiboPrice, AmiiboPriceHistory
|
||||
)
|
||||
|
@ -22,9 +23,9 @@ class ColectionResource(resources.ModelResource):
|
|||
model = Collection
|
||||
|
||||
|
||||
class AmiiboResource(resources.ModelResource):
|
||||
class AmiiboFigureResource(resources.ModelResource):
|
||||
class Meta:
|
||||
model = Amiibo
|
||||
model = AmiiboFigure
|
||||
|
||||
|
||||
class AmiiboShopResource(resources.ModelResource):
|
||||
|
@ -32,18 +33,23 @@ class AmiiboShopResource(resources.ModelResource):
|
|||
model = AmiiboShop
|
||||
|
||||
|
||||
class AmiiboCardResource(resources.ModelResource):
|
||||
class Meta:
|
||||
model = AmiiboCard
|
||||
|
||||
|
||||
class CollectionAdmin(ImportExportModelAdmin, reversion.VersionAdmin):
|
||||
resource_class = ColectionResource
|
||||
|
||||
list_display = ('name_eu', 'amiibo_number', 'have_cards', )
|
||||
list_display = ('name_eu', 'amiibo_number', )
|
||||
|
||||
def amiibo_number(self, obj):
|
||||
return obj.amiibos.count()
|
||||
amiibo_number.short_description = 'Amiibos'
|
||||
|
||||
|
||||
class AmiiboAdmin(ImportExportModelAdmin, reversion.VersionAdmin):
|
||||
resource_class = AmiiboResource
|
||||
class AmiiboFigureAdmin(ImportExportModelAdmin, reversion.VersionAdmin):
|
||||
resource_class = AmiiboFigureResource
|
||||
|
||||
list_display_links = ('name_eu', )
|
||||
list_display = ('statue_image', 'name_eu', 'collection',)
|
||||
|
@ -63,7 +69,7 @@ class AmiiboAdmin(ImportExportModelAdmin, reversion.VersionAdmin):
|
|||
|
||||
|
||||
class AmiiboCardAdmin(ImportExportModelAdmin, reversion.VersionAdmin):
|
||||
resource_class = AmiiboResource
|
||||
resource_class = AmiiboCardResource
|
||||
|
||||
list_display_links = ('name_eu', )
|
||||
list_display = ('image_image', 'name_eu', 'collection', 'dice', 'rps', )
|
||||
|
@ -84,7 +90,6 @@ class AmiiboShopAdmin(ImportExportModelAdmin, reversion.VersionAdmin):
|
|||
list_editable = ('check_price', )
|
||||
|
||||
|
||||
|
||||
class AmiiboPriceAdmin(reversion.VersionAdmin):
|
||||
pass
|
||||
|
||||
|
@ -94,7 +99,7 @@ class AmiiboPriceHistoryAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
admin.site.register(Collection, CollectionAdmin)
|
||||
admin.site.register(Amiibo, AmiiboAdmin)
|
||||
admin.site.register(AmiiboFigure, AmiiboFigureAdmin)
|
||||
admin.site.register(AmiiboShop, AmiiboShopAdmin)
|
||||
admin.site.register(AmiiboPrice, AmiiboPriceAdmin)
|
||||
admin.site.register(AmiiboPriceHistory, AmiiboPriceHistoryAdmin)
|
||||
|
|
|
@ -7,7 +7,7 @@ from .models import Collection, AmiiboPrice
|
|||
def collections(request):
|
||||
return {
|
||||
'COLLECTIONS_FIGURES': Collection.objects.all().order_by('name_eu'),
|
||||
'COLLECTIONS_CARDS': Collection.objects.filter(have_cards=True).order_by('name_eu'),
|
||||
# 'COLLECTIONS_CARDS': Collection.objects.filter(have_cards=True).order_by('name_eu'),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import amiibofindr.apps.amiibo.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('amiibo', '0018_amiiboshop_check_price'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AmiiboCard',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('number', models.IntegerField(default=1)),
|
||||
('name', models.CharField(max_length=60)),
|
||||
('name_en', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_es', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_fr', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_it', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_de', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_eu', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_jp', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('name_us', models.CharField(max_length=64, null=True, blank=True)),
|
||||
('slug', models.SlugField(max_length=60)),
|
||||
('image', models.ImageField(upload_to=amiibofindr.apps.amiibo.models.image_card_upload)),
|
||||
('dice', models.IntegerField(default=1)),
|
||||
('rps', models.CharField(default=1, max_length=1, choices=[(1, b'Rock'), (2, b'Paper'), (3, b'Scissors')])),
|
||||
],
|
||||
options={
|
||||
'ordering': ('collection', 'number', 'name'),
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='collection',
|
||||
name='have_cards',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibocard',
|
||||
name='collection',
|
||||
field=models.ForeignKey(related_name='cards_qs', to='amiibo.Collection'),
|
||||
),
|
||||
]
|
|
@ -7,7 +7,7 @@ from django.db import models, migrations
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('amiibo', '0019_auto_20150827_1825'),
|
||||
('amiibo', '0018_amiiboshop_check_price'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import amiibofindr.apps.amiibo.models
|
||||
|
||||
|
||||
BACKUP = {}
|
||||
|
||||
|
||||
def backup_images(apps, schema_editor):
|
||||
Amiibo = apps.get_model("amiibo", "Amiibo")
|
||||
for amiibo in Amiibo.objects.all():
|
||||
BACKUP[amiibo.pk] = {
|
||||
'box': amiibo.box,
|
||||
'statue': amiibo.statue,
|
||||
}
|
||||
|
||||
def restore_images(apps, schema_editor):
|
||||
AmiiboFigure = apps.get_model("amiibo", "AmiiboFigure")
|
||||
for pk, images in BACKUP.items():
|
||||
amiibo = AmiiboFigure.objects.get(pk=pk)
|
||||
amiibo.box = images['box']
|
||||
amiibo.statue = images['statue']
|
||||
amiibo.save()
|
||||
|
||||
|
||||
def convert_all_to_figures(apps, schema_editor):
|
||||
Amiibo = apps.get_model('amiibo', 'Amiibo')
|
||||
AmiiboFigure = apps.get_model('amiibo', 'AmiiboFigure')
|
||||
for amiibo in Amiibo.objects.all():
|
||||
figure = AmiiboFigure(amiibo_ptr=amiibo)
|
||||
for key, value in amiibo.__dict__.items():
|
||||
figure.__dict__[key] = value
|
||||
figure.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('amiibo', '0020_amiiboshop_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
# From removed migrations
|
||||
migrations.RunSQL("DROP TABLE amiibo_amiibocard;"),
|
||||
migrations.RunSQL("ALTER TABLE amiibo_collection DROP COLUMN have_cards;"),
|
||||
# Fresh start
|
||||
migrations.RunPython(backup_images),
|
||||
migrations.RemoveField(
|
||||
model_name='amiibo',
|
||||
name='box',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='amiibo',
|
||||
name='statue',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='link_de',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='link_en',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='link_es',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='link_fr',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='link_it',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='name_de',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='name_en',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='name_es',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='name_fr',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='name_it',
|
||||
field=models.CharField(max_length=64, null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='amiibo',
|
||||
name='type',
|
||||
field=models.CharField(default=b'figure', max_length=9, choices=[(b'figure', b'Figure'), (b'card', b'Card')]),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AmiiboCard',
|
||||
fields=[
|
||||
('amiibo_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='amiibo.Amiibo')),
|
||||
('image', models.ImageField(upload_to=amiibofindr.apps.amiibo.models.image_card_upload)),
|
||||
('dice', models.IntegerField(default=1)),
|
||||
('rps', models.CharField(default=1, max_length=1, choices=[(1, b'Rock'), (2, b'Paper'), (3, b'Scissors')])),
|
||||
],
|
||||
options={
|
||||
'ordering': ('collection', 'collection_number', 'name_eu'),
|
||||
},
|
||||
bases=('amiibo.amiibo',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AmiiboFigure',
|
||||
fields=[
|
||||
('amiibo_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='amiibo.Amiibo')),
|
||||
('statue', models.ImageField(upload_to=amiibofindr.apps.amiibo.models.image_statue_upload)),
|
||||
('box', models.ImageField(null=True, upload_to=amiibofindr.apps.amiibo.models.image_box_upload, blank=True)),
|
||||
],
|
||||
bases=('amiibo.amiibo',),
|
||||
),
|
||||
migrations.RunPython(convert_all_to_figures),
|
||||
migrations.RunPython(restore_images),
|
||||
]
|
|
@ -39,7 +39,6 @@ class Collection(models.Model):
|
|||
name_eu = models.CharField(max_length=128)
|
||||
name_jp = models.CharField(max_length=128, blank=True, null=True)
|
||||
name_us = models.CharField(max_length=128, blank=True, null=True)
|
||||
have_cards = models.BooleanField(default=False)
|
||||
|
||||
@property
|
||||
def amiibos(self):
|
||||
|
@ -58,21 +57,38 @@ class Collection(models.Model):
|
|||
|
||||
|
||||
class Amiibo(models.Model):
|
||||
FIGURE = 'figure'
|
||||
CARD = 'card'
|
||||
AMIIBO_TYPES = (
|
||||
(FIGURE, 'Figure'),
|
||||
(CARD, 'Card'),
|
||||
)
|
||||
|
||||
collection = models.ForeignKey(Collection, related_name='amiibos_qs')
|
||||
collection_number = models.IntegerField(blank=True, null=True)
|
||||
type = models.CharField(max_length=9, default=FIGURE, choices=AMIIBO_TYPES)
|
||||
|
||||
model_number = models.CharField(max_length=20, blank=True, null=True)
|
||||
|
||||
slug = models.SlugField(max_length=64)
|
||||
|
||||
statue = models.ImageField(upload_to=image_statue_upload)
|
||||
box = models.ImageField(upload_to=image_box_upload, blank=True, null=True)
|
||||
name_en = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_es = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_fr = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_it = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_de = models.CharField(max_length=64, blank=True, null=True)
|
||||
|
||||
name_eu = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_jp = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_us = models.CharField(max_length=64, blank=True, null=True)
|
||||
|
||||
# Links
|
||||
link_en = models.CharField(max_length=64, blank=True, null=True)
|
||||
link_es = models.CharField(max_length=64, blank=True, null=True)
|
||||
link_fr = models.CharField(max_length=64, blank=True, null=True)
|
||||
link_it = models.CharField(max_length=64, blank=True, null=True)
|
||||
link_de = models.CharField(max_length=64, blank=True, null=True)
|
||||
|
||||
link_eu = models.CharField(max_length=255, blank=True, null=True)
|
||||
link_jp = models.CharField(max_length=255, blank=True, null=True)
|
||||
link_us = models.CharField(max_length=255, blank=True, null=True)
|
||||
|
@ -93,6 +109,18 @@ class Amiibo(models.Model):
|
|||
def get_absolute_url(self):
|
||||
return ('amiibo:amiibo', [self.collection.slug, self.slug])
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.name_eu) or u''
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.name_eu
|
||||
|
||||
|
||||
class AmiiboFigure(Amiibo):
|
||||
statue = models.ImageField(upload_to=image_statue_upload)
|
||||
box = models.ImageField(upload_to=image_box_upload, blank=True, null=True)
|
||||
|
||||
@property
|
||||
def image_box(self):
|
||||
return 'images/amiibo/{}/{}-box.jpg'.format(
|
||||
|
@ -105,15 +133,8 @@ class Amiibo(models.Model):
|
|||
self.collection.slug, self.slug
|
||||
)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.name_eu) or u''
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.name_eu
|
||||
|
||||
|
||||
class AmiiboCard(models.Model):
|
||||
class AmiiboCard(Amiibo):
|
||||
ROCK = 1
|
||||
PAPER = 2
|
||||
SCISSORS = 3
|
||||
|
@ -123,27 +144,13 @@ class AmiiboCard(models.Model):
|
|||
(SCISSORS, 'Scissors'),
|
||||
)
|
||||
|
||||
collection = models.ForeignKey(Collection, related_name='cards_qs')
|
||||
number = models.IntegerField(default=1)
|
||||
name = models.CharField(max_length=60)
|
||||
|
||||
name_en = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_es = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_fr = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_it = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_de = models.CharField(max_length=64, blank=True, null=True)
|
||||
|
||||
name_eu = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_jp = models.CharField(max_length=64, blank=True, null=True)
|
||||
name_us = models.CharField(max_length=64, blank=True, null=True)
|
||||
|
||||
slug = models.SlugField(max_length=60)
|
||||
image = models.ImageField(upload_to=image_card_upload)
|
||||
|
||||
dice = models.IntegerField(default=1)
|
||||
rps = models.CharField(choices=RPS_CHOICES, default=ROCK, max_length=1)
|
||||
|
||||
class Meta:
|
||||
ordering = ('collection', 'number', 'name', )
|
||||
ordering = ('collection', 'collection_number', 'name_eu', )
|
||||
|
||||
def __unicode__(self):
|
||||
return u"{} {}".format(self.number, self.name)
|
||||
|
|
Loading…
Reference in New Issue