我在尝试保存时收到错误消息“NoneType”对象不可调用Campaign
。在 Django 中,这是否意味着一旦我保存了我的对象SingleVoucherReward()
,我就无法访问它并且无法将它分配给我的 Campaign 对象?
single_voucher_reward = SingleVoucherReward()
single_voucher_reward.description = "test"
single_voucher_reward.save()
Campaign.participant_reward(single_voucher_reward)
Campaign.save()
模型:
class Campaign(models.Model):
name = models.CharField(max_length=60, help_text="Give your campaign a name i.e Xmas Offer")
participant_reward_content_type = models.ForeignKey(ContentType,
editable=False,
related_name='%(app_label)s_%(class)s_as_participant',
)
participant_reward_object_id = models.PositiveIntegerField()
participant_reward = generic.GenericForeignKey('participant_reward_content_type', 'participant_reward_object_id')