angularjs - Angulary and Django REST -


how can filtred queryset?

simply example:

.controller('tviewcontroller', ["$scope", "$stateparams", "ad", "banner", function($scope, $stateparams, ad, banner) {     $scope.ad = ad.get({ ad_id: $stateparams.ad_id });     $scope.banners = banner.query(); }]) 

and

class cbanner(models.model):     image = models.imagefield(upload_to="img")     ad = models.foreignkey(cads, null=true, blank=true) class cads(models.model):     name = models.charfield(max_length=80, null=true, blank=true) 

they both have viewset, serializer , routing register

class adsviewer(viewsets.modelviewset):     queryset = cads.objects.all()     serializer_class = adsserializer etc...  

how can filtered this: $scope.banners = banner.query(); banners ad(foreignkey) = ad_id?

you need add query parameter url, such as:

http://example.com/api/ads/?ad_fk=5 

in adsviewer:

def get_queryset(self):     """     view should return list of ads filtered proper foreign key     """     ad_fk = self.request.query_params.get('ad_fk', none)     return cads.objects.filter(ad=ad_fk) 

for more info see doc


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -