標準の Django 型にマップする Django でいくつかの型を作成しようとしています。カスタム モデル フィールドのドキュメントは、複雑なケースに入ります。便利なメソッドがたくさんあるクラスから基本的な Django 型を保存したいだけです。
たとえば、トランプを保管している場合、次のようなものが必要です。
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): ...
...
モデルに次のようなものを持たせたい:
class my_game(models.Model):
ante = models.IntegerField()
bonus_card = Card() # Really stored as an models.IntegerField()
....
答えは、正しいタイプから継承し、カードに特別な名前の get/store フィールドを追加し、名前をinit () に変更するように見えると予想しています。サンプルコードやより良いドキュメントを持っている人はいますか?