0
我越來越努力拯救運動,我認爲這個問題是在哪裏bundle.obj.participant_reward(_SingleVoucherReward())
我嘗試創建並保存新的資源之前鏈接它時,下面的錯誤。SingleVoucherReward」對象不是可調用的」
錯誤信息:SingleVoucherReward」對象不是可調用
注:對象SingleVoucherReward
保存到數據庫成功的錯誤是連接並將其保存到Campaign
def hydrate(self, bundle, request=None):
"""
Tastypie uses a 'hydrate' cycle to take serializated data from the client
and turn it into something the data model can use.
"""
if bundle.data.get('SingleVouc'):
_SingleVoucherReward = SingleVoucherReward(
description = "test",
subsequent_purchases = 1,
auto_reward = 1
)
_SingleVoucherReward.save()
bundle.obj.participant_reward(_SingleVoucherReward())
return bundle
型號:
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')
謝謝你,這是非常有益的。 – GrantU