I am new to using django and tastypie. And I'm trying to make a filter to
know how many players belong to a club, sending the id of the club, where
the field in question has a relation to the collection Club
I'm trying this:
Código (Python):
class PlayerResource(resources.MongoEngineResource):
PlayerClub = fields.ReferencedListField(of='Rela.Resource.ClubResource',
attribute='PlayerClub', full=True, null=True)
def apply_filters(self, request, applicable_filters):
base_object_list = super(PlayerResource, self
).apply_filters(request, applicable_filters)
query = request.GET.get('PlayerClub', None)
if query:
qset = (
Q(PlayerClubname__icontains=query)
)
base_object_list = base_object_list.filter(qset).distinct()
return base_object_list
class Meta:
queryset = Player.objects.all()
allowed_methods = ('get', 'post', 'put', 'delete')
list_allowed_methods = ['get', 'post','put', 'delete']
authorization = Authorization()
#fields = ['id', 'PlayerName', 'PlayerAge']
resource_name = 'Player'
filtering = {
#'PlayerClub': ALL_WITH_RELATIONS,
'PlayerAge' : ALL,
'PlayerClub': 'icontains',
}
def determine_format(self, request):
return "application/json"
But it gives me says: 'exact' is not an allowed filter on the 'PlayerClub'
field.
I do not know if what I'm doing is good or if it makes sense?
My solitação GET is: *
http://localhost:8080/Rela/api/v1/Player?PlayerClub=519dd7b28774a704d4a97748
*
Someone can help me?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.