我正在尝试按照本指南https://docs.djangoproject.com/en/2.1/howto/custom-model-fields/创建自己的自定义模型字段
class Hand:
"""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
# ... (other possibly useful methods omitted) ...
下一步是(我们假设模型上的手属性是手的一个实例)
example = MyModel.objects.get(pk=1)
print(example.hand.north)
new_hand = Hand(north, east, south, west)
example.hand = new_hand
example.save()
“我们假设模型上的手属性是手的一个实例”
有人可以提供例子吗?