tastypie save_m2m,TagRelatedManager计算结果为False

时间:2015-12-01 13:34:36

标签: python tastypie django-tagging django-related-manager

实际上,我正在尝试保存包含来自django-tagulous

TagField的tastypie模型资源

以下是我的模型和资源:

# models.py
class SimpleModel(models.Model):
    topics = tagulous.models.TagField()
    title = models.CharField(max_length=100)


# resources.py
class TopicResource(ModelResource):
    class Meta:
        queryset = SimpleModel.topics.tag_model.objects.all()
        authentication = Authentication()
        authorization = Authorization()


class SimpleModelResource(ModelResource):
    tags = fields.ToManyField(TopicResource, attribute='topics', full=True, null=True)

    class Meta:
        queryset = SimpleModel.objects.all()
        authentication = Authentication()
        authorization = Authorization()

卷曲部分:

curl --request POST --dump-header - --header 'Content-Type: application/json' --data '{"tags": ["/api/v1/topic/1/"], "title": "A bad dream"}' localhost:8000/api/v1/simplemodel/

shell不会返回任何错误,但是,标记与新对象没有关联。

通过覆盖ModelResource save_m2m method,在super调用标记对象之前(print bundle.data ['tags']),然后在super(SimpleModelResource, self).save_m2m(bundle) tastypie查找相关内容与tags字段关联的manager,返回related_mngr,但是当使用:if not related_mngr进行评估时,它会评估为True滑动m2m关联。

0 个答案:

没有答案