I'm trying to make some types in Django that map to standard Django types. The custom model field documentation goes into complicated cases; I just want to store a basic Django type from a class with a bunch of handy methods.
For example, if I were storing playing cards, I want something like:
class Card(object):
""" A playing card. """
def as_number(self):
""" returns a number from 1 (Ace of Clubs) and 52 (King of Spades)."""
return self.number + self.suit_rank() * 13
def __unicode(self): ...
def is_highest(self, other_cards, trump=None):...
def __init__(self, number, suit): ...
...
I want my models to have something like:
class my_game(models.Model):
ante = models.IntegerField()
bonus_card = Card() # Really stored as an models.IntegerField()
....
I'm expecting the answer will look like inheriting from the correct type, adding some specially named get/store fields for card, and renaming init(). Does anyone have sample code or better documentation?