尝试在Django 1.9文档中关注the example mentionned,我无法按照说明进行操作。
以下代码我坚持:
fields.py
class Hand(object):
"""A hand of cards (bridge style)"""
def __init__(self, north, east, south, west):
# Input parameters are lists of cards ('Ah', '9s', etc)
self.north = north
self.east = east
self.south = south
self.west = west
class HandField(models.Field):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 104
super(HandField, self).__init__(*args, **kwargs)
def deconstruct(self):
name, path, args, kwargs = super(HandField, self).deconstruct()
del kwargs["max_length"]
return name, path, args, kwargs
models.py
from django.db import models
from .fields import HandField
class Game(models.Model)
hand = HandField()
但是,在尝试迁移时,我看到未创建手栏:
...
-- Create model Game
--
CREATE TABLE "django_quizz_game" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT);
--
...
我错过了什么? 顺便说一句,我无法弄清楚Hand类和HandField类(应该)之间的关系。