python - TastyPie Django: ManyToMany field fails to load -


so have in models:

class narative(models.model):     voice = models.filefield(upload_to='uploads/%y/%m/%d',blank = true, null=true)      def     filename(self):         return os.path.basename(self.voice.name)      def clean(self):         return os.path.basename(self.voice.name)      def __unicode__(self):         return self.filename()   class geolocations(models.model):     name = models.charfield(max_length=255)     parent = models.foreignkey('self', blank=true,null=true)     sort = models.integerfield(default=0, blank=true,null=true)     description = htmlfield()     locations = models.manytomanyfield('locgeo')     excerpt = models.charfield(max_length=4096)     icon = models.charfield(max_length=255, blank = true, null=true)     tags = models.charfield(max_length=255, blank = true, null=true)     categories = models.manytomanyfield('categories',blank = true, null=true)     photos = models.manytomanyfield('photo', blank = true, null=true)     narations = models.manytomanyfield('narative', blank = true, null=true) 

and in api.py

class narres(modelresource):     class meta:         queryset = narative.objects.all()         resource_name = 'nar'  class entryresource(modelresource):     locations = fields.tomanyfield('self', filter_locations_per_bundle, full=true, null=true)     locgeo = fields.tomanyfield('myapp.api.locgeores', 'locations', full=true, null=true)     photos = fields.tomanyfield('myapp.api.photoresource','photos', full=true, null=true)     narative = fields.tomanyfield('myapp.api.narres','narative', full=true, null=true)      class meta:         queryset = geolocations.objects.all()         resource_name = 'locations'         fields = ['parent','narative','id','name','description','excerpt','lgeo','icon','tags','categories','photos','locations'] 

problem is, json output lists narative empty array:

... locations: [ ], locgeo: [ { id: 1, latitude: "33", longitude: "22", name: "location", radius: 140, resource_uri: "/api/v1/lgeo/1/" } ], name: "location", narative: [ ], photos: [ { id: 6, name: "location", photo: "/media/uploads/2014/04/18/img_1643_result.jpg", resource_uri: "/api/v1/photos/6/" }, ... 

when know fact there entry record (i can see when list narative resource).

what doing wrong?

as indicated in model name of foreign key "narations". in resource, referring "narative".

the modified line should be:

narative = fields.tomanyfield('myapp.api.narres','narations', full=true, null=true) 

that fixed it.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -