Filter users by user group in tastypie -


this user resource class

class userresource(modelresource):     class meta:         queryset = user.objects.all()         allowed_methods = ['get', 'post', 'put', 'patch']         resource_name = 'user'         excludes = ['password']         #authentication = sessionauthentication()         #authorization = djangoauthorization()         authorization = authorization()         authentication = authentication()         always_return_data = true         filtering = {             'id': all,             'username': all,             'groups': all_with_relations         } 

i want filter user group names. /api/v1/user/?format=json&groups__name=group_name

the above format not working. how can filter in request?

you have add relational fields model going use resource. in first place have create model resource group model. create many field in userresource linked groupresource.

something this:

class groupresource(modelresource):     class meta:         queryset = group.objects.all()         resource_name = 'group'         authorization = authorization()         authentication = authentication()         always_return_data = true         filtering = {             'id': all,             'name': all,         }   class userresource(modelresource):     groups = fields.tomanyfield(groupresource, 'groups',                                 blank=true)     class meta:         queryset = user.objects.all()         allowed_methods = ['get', 'post', 'put', 'patch']         resource_name = 'user'         excludes = ['password']         #authentication = sessionauthentication()         #authorization = djangoauthorization()         authorization = authorization()         authentication = authentication()         always_return_data = true         filtering = {             'id': all,             'username': all,             'groups': all_with_relations         } 

the reason of tastypie has know relational object authorization, authentication, resource_name , rest bunch of settings can't populate itself.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -