2π
The problem is not the queryset, but standard Python scoping. You need to think about where the value for restaurant is supposed to be coming from.
In your case, it is clearly coming from the URL; assuming you have a URL something like this:
url(r'^restaurant/(?P<restaurant_id>\d+)/employees/$', ...)
named capturing group, that value will be stored in self.kwargs['restaurant_id']
. So you should use that in the filter.
Note also that you can use restaurant_id
directly as the field, rather than doing a JOIN
So:
queryset = Employee.objects.filter(restaurant_id=self.kwargs['restaurant'])
0π
You are not providing restaurant into the get_queryset. Probably it should be like that:
def get_queryset(self):
self.restaurant = get_object_or_404(Restaurant, name=self.args[0])
return Emploee.objects.filter(pk=self.restaurant)
- [Answered ]-Get annual count within the given range of years
- [Answered ]-Django with mongodb using pymongo without using ORM
- [Answered ]-Testing with Django: how to display all characters when using assertEqual with json object?
- [Answered ]-Restrict foreign key values according to request.user in django
- [Answered ]-How to show API description with django_rest_swagger 2.1.1
0π
try this β
queryset = Employee.objects.filter(restaurant__pk=pk_value)
you should pass pk_value here and restaurant field should be foreign key to other table. You can check by passing pk_value = 1 as you are doing in shell.
hope this helps. for more info check django model docs β https://docs.djangoproject.com/en/1.10/topics/db/models/
- [Answered ]-How to use two different email addresses for emails sending?
- [Answered ]-Django calling another model's upload_to inside a model
- [Answered ]-Needed django users and subusers with limited permissions
- [Answered ]-Python and Django Insert Strings into a Database
- [Answered ]-Getting "This field is required" error even though I set null=True and blank=True