gpt4 book ai didi

python - 错误 : object has no attribute 'get_via_uri' "in post object in tastypie

转载 作者:行者123 更新时间:2023-11-28 19:21:05 24 4
gpt4 key购买 nike

我是 django 的新手,在发布数据时遇到错误:

{    "name": "My family",
"title": "Wassup",
"gallery":"/api/v1/gallery/1/"
}

到终点:http://127.0.0.1:8000/api/v1/images/
"error_message": "'Gallery' 对象没有属性 'get_via_uri'"

模型.py

class Gallery(models.Model):
name = models.CharField(max_length=64)

def __unicode__(self):
return unicode(self.name)


class Image(models.Model):
gallery = models.ForeignKey(Gallery)
name = models.CharField(max_length=64)
title = models.CharField(max_length=255)

资源.py

class GalleryResource(ModelResource):
images = fields.ToManyField(
'gallery_app.resources.ImageResource',
'images',
full=True)

class Meta:
queryset = Gallery.objects.all()
authorization = Authorization()
resource_name = 'gallery'


class ImageResource(ModelResource):
gallery = fields.ForeignKey(Gallery, 'gallery')

class Meta:
queryset = Image.objects.all()
authorization = Authorization()
resource_name = 'images'

点卡住

Django==1.6.5
Pillow==2.5.1
South==1.0
argparse==1.2.1
django-tastypie==0.11.1
python-dateutil==2.2
python-mimeparse==0.1.4
six==1.7.3
wsgiref==0.1.2

请推荐一些基于tastypie api的好项目供引用。谢谢。

最佳答案

您指的是 ImageResource 中的模型库,您应该指的是 GalleryResource。

class ImageResource(ModelResource):
gallery = fields.ForeignKey(GalleryResource, 'gallery')

class Meta:
queryset = Image.objects.all()
authorization = Authorization()
resource_name = 'images'

引用:http://django-tastypie.readthedocs.io/en/latest/resources.html#reverse-relationships

关于python - 错误 : object has no attribute 'get_via_uri' "in post object in tastypie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24765006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com