2010-07-01 19:37:43 +00:00
|
|
|
from django.db import models
|
2010-09-16 18:11:55 +00:00
|
|
|
from mtgweb.lib.mtg import mtg
|
2010-07-01 19:37:43 +00:00
|
|
|
|
|
|
|
# Create your models here.
|
2010-09-16 18:11:55 +00:00
|
|
|
class CardType(models.Model):
|
|
|
|
name = models.CharField(max_length=200, unique=True, db_index=True)
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
2010-08-26 19:19:32 +00:00
|
|
|
class Attribute(models.Model):
|
|
|
|
name = models.CharField(max_length=200, unique=True, db_index=True)
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
2010-09-16 18:11:55 +00:00
|
|
|
class Card(models.Model, mtg.Card):
|
2010-08-26 19:19:32 +00:00
|
|
|
name = models.CharField(max_length=200, unique=True)
|
2010-09-16 18:11:55 +00:00
|
|
|
type = models.ForeignKey(CardType)
|
2010-08-26 19:19:32 +00:00
|
|
|
attributes = models.ManyToManyField(Attribute)
|
|
|
|
cost = models.CharField(max_length=80)
|
|
|
|
converted_cost = models.IntegerField(default=0)
|
|
|
|
power = models.CharField(max_length=10)
|
|
|
|
toughness = models.CharField(max_length=10)
|
2010-09-21 19:46:28 +00:00
|
|
|
rarity = models.CharField(max_length=1)
|
2010-08-26 19:19:32 +00:00
|
|
|
text = models.TextField()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
class Deck(models.Model):
|
|
|
|
name = models.CharField(max_length=80)
|
2010-09-17 21:28:46 +00:00
|
|
|
cards = models.ManyToManyField(Card, through='Included')
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
class Included(models.Model):
|
|
|
|
card = models.ForeignKey(Card)
|
|
|
|
deck = models.ForeignKey(Deck)
|
|
|
|
count = models.IntegerField(default=0)
|
|
|
|
def __unicode__(self):
|
|
|
|
return '{0}x {1}'.format(self.count, self.card)
|