Added UserAmiibo
This commit is contained in:
parent
fbf5eeb795
commit
04a249614d
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('amiibo', '0021_auto_20150907_2143'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UserAmiibo',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('want', models.BooleanField(default=False)),
|
||||
('have', models.BooleanField(default=False)),
|
||||
('trade', models.BooleanField(default=False)),
|
||||
('date', models.DateTimeField(auto_now=True)),
|
||||
('_amiibo', models.ForeignKey(to='amiibo.Amiibo')),
|
||||
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -4,6 +4,7 @@
|
|||
import os
|
||||
|
||||
# django
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
|
@ -105,6 +106,17 @@ class Amiibo(models.Model):
|
|||
|
||||
visible = models.BooleanField(default=True)
|
||||
|
||||
_types = {
|
||||
'figure': 'amiibo.AmiiboFigure',
|
||||
'card': 'amiibo.AmiiboCard',
|
||||
}
|
||||
|
||||
def as_type(self):
|
||||
""" Returns the amiibo as the correct type model """
|
||||
# TODO: Improve this, because queries. Change to a manager.
|
||||
model = apps.get_model(self._types[self.type])
|
||||
return model.objects.get(pk=self.pk)
|
||||
|
||||
def get_all_names(self):
|
||||
result = u''
|
||||
for key, value in self.__dict__.items():
|
||||
|
@ -277,3 +289,17 @@ class AmiiboPriceHistory(models.Model):
|
|||
self.diff, self.currency,
|
||||
self.date
|
||||
)
|
||||
|
||||
|
||||
class UserAmiibo(models.Model):
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||
_amiibo = models.ForeignKey(Amiibo)
|
||||
|
||||
want = models.BooleanField(default=False)
|
||||
have = models.BooleanField(default=False)
|
||||
trade = models.BooleanField(default=False)
|
||||
date = models.DateTimeField(auto_now=True)
|
||||
|
||||
@property
|
||||
def amiibo(self):
|
||||
return self._amiibo.as_type()
|
||||
|
|
Loading…
Reference in New Issue