If I try to filter a field in a related object, then Tastypie returns an error. For example, launch
curl -H "Accept: application/json" \
"http://localhost:8080/wordgame/api/v1/rounds/?format=json&players__username=moe"
returns “Search is not allowed more than one level in the players field. Essentially, I'm trying to do what I can do now in the Django shell:
Round.objects.all().filter(players__username=moe.username)
I use the following code, which I simplified for brevity:
class RoundResource(ModelResource):
players = fields.ManyToManyField(UserResource, 'players',full=True)
. . .
class Meta:
queryset = Round.objects.all()
resource_name = 'rounds'
filtering = {
'players': ALL,
}
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'players'
filtering = {
'username': ALL,
}
class Round(models.Model):
players = models.ManyToManyField(User)
word = models.CharField(max_length=75)
. . .
I assume that since UserResource defines a filter in the "username" field, this should work, but it is not. I even tried adding "players__username" to the filter in RoundResource, however that didn't work either.
GitHub, . , , . Tastypie GitHub, , , 1) , 2) , .