2016-04-26 7 views
0

Warum meine API zeigt keine PK von Mietmodell? Ich habe tastypie für Rest api benutzt. Id der Galerie-Modell wird gezeigt, aber nicht der Vermietung model.This ist mein Code für apiMeine API zeigt keine pk von Mietmodell

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() 
+0

Ist das PK-Feld nicht wirklich ID in Django? – 2ps

+0

Ich versuchte ID, aber zeigte ID nicht, also versuchte ich, pk zu verwenden. – milan

+0

Bitte zeigen Sie Ihre Modelldefinition 'Rental' an –

Antwort

0

Weil Sie haben detail_uri_name = 'slug' in RentalResource. Entferne diese Zeile.