我有这个:
class Character(models.Model):
weapon = models.ForeignKey(item, related_name='weapon')
shield = models.ForeignKey(item, related_name='shield')
...
class Item(models.Model):
nom = models.CharField(max_length=30)
choices = (
('weapon', 'weapon'),
('shield', 'shield'),
...
)
typeOf = models.CharField(max_length=15, choices=choices)
...
我想通过item.typeof的名称更新我的字符字段,但它不起作用。
character[item.typeof] = item
character.save()
我该怎么做?