【问题标题】:My API is not showing any pk of rental model我的 API 没有显示任何租赁模型的 pk
【发布时间】:2016-08-19 16:59:39
【问题描述】:

为什么我的 api 没有显示任何租赁模型的 pk?我已经将美味派用于休息 api。显示画廊模型的 ID,但不显示租赁模型的 ID。这是我的 api 代码

class RentalResource(MultipartResource,ModelResource):
    gallery = fields.ToManyField('rentals.api.api.GalleryResource', 'gallery', related_name='rental',full=True)
    class Meta:
        queryset = Rental.objects.all()
        resource_name = 'rental'
        detail_uri_name = 'slug'
        allowed_methods = ['get', 'post', 'put']
        fields = ['listingName','id','slug','property','city','place','ownerName','room','water','amenities','price','summary','phoneNumber','email']
        filtering = { "property" : ALL , "id":All, "city":ALL, "place":('exact', 'startswith',), "room":ALL,"price":ALL,"listingName":ALL,"slug":ALL}
        authorization = DjangoAuthorization()


class GalleryResource(ModelResource):
    rental = fields.ForeignKey(RentalResource, 'rental',full=False, null=True, blank=True)
    class Meta:
        queryset = Gallery.objects.all()
        resource_name = 'gallery'
        allowed_methods = ['get','post','put']
        authorization = DjangoAuthorization()

【问题讨论】:

  • 在django中pk字段不是真的叫id吗?
  • 我尝试使用 id 但没有显示 id 所以我尝试使用 pk。
  • 请出示您的Rental模型定义

标签: python django tastypie django-1.9


【解决方案1】:

因为您在RentalResource 中有detail_uri_name = 'slug'。删除此行。

【讨论】:

    猜你喜欢
    • 2014-11-25
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    相关资源
    最近更新 更多