Tastypie relationship fields on obj_get_list -
i have standard user/group many many relationship following simplified definition:
class groupresource(modelresource): users = fields.tomanyfield(userresource, 'group_set') class meta: cache = simplecache() queryset = group.objects.all() resource_name = "hr/group"
when list groups returns group along list of uris of users connected group. however, our production system starting quite large , group can have hundreds of users in it. becoming painstakingly slow return list of groups, since each group returns list of users connected group.
is there way exclude linked users obj_get_list, include users when viewing group instance? or there solution problem fit better?
you need specify callable
use_in
argument fields.tomanyfield
returns false
if current request corresponds get_list end point.
example code
def is_not_group_get_list_end_point(bundle): # todo: use dynamically generated path here. if bundle.request.get_full_path() == '/api/v1/hr/group/': return false return true class groupresource(modelresource): users = fields.tomanyfield(userresource, 'group_set', use_in=is_not_group_get_list_end_point) class meta: cache = simplecache() queryset = group.objects.all() resource_name = "hr/group"
Comments
Post a Comment