0

Trying to follow the example mentionned in Django 1.9 documentation, I'm unable to make it works as described.

Here's the code I'm stuck with :

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()

However, when trying to migrate, I see the hand column is not created :

...
-- Create model Game
--
CREATE TABLE "django_quizz_game" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT);
--
...

What am I missing ? btw, I can't figure out where the relationship between the Hand class and the HandField class (should) occur.

Lapin-Blanc
  • 1,945
  • 1
  • 17
  • 26
  • 1
    Have you read the whole of that documentation page? Your HandField class is incomplete and needs a lot more adding to it before it can be migrated. – solarissmoke Apr 16 '16 at 08:09
  • Thank you for the answer. English is not my mother tongue and it was not clear for me that I had to go through "useful methods" to make it work. – Lapin-Blanc Apr 16 '16 at 11:49

0 Answers0