SingleVoucherReward'对象不可调用“

时间:2013-10-31 14:03:42

标签: python django

我在尝试保存广告系列时收到以下错误我认为问题出现在bundle.obj.participant_reward(_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')

1 个答案:

答案 0 :(得分:4)

你有一个名为SingleVoucherReward的模型,然后初始化一个名为SingleVoucherReward的{​​{1}}实例,但你的模型没有定义_SingleVoucherReward方法,所以你得到这个{ {1}}错误。

__call__

应该是:

not callable

顺便说一句,命名bundle.obj.participant_reward(_SingleVoucherReward()) 更明确表示它是一个实例。