实际上,我试图保存一个tastypie模型资源,它包含来自django-tagulous的TagField
以下是我的模型和资源:
# 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)捆绑数据['tags']),然后在super(SimpleModelResource, self).save_m2m(bundle)
tastype中查找与tags字段关联的相关管理器,返回相关的\u mngr,但是当使用if not related_mngr
对其求值时,它求值为跳过m2m关联。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐