4
In that case you probably want to use a ListAPIView
(docs) and filter based on the primary key of the Animal
, so:
class MyAnimalSex(generics.ListAPIView):
queryset = AnimalSex.objects.all()
serializer_class = AnimalSexSerializer
def get_queryset(self):
return super().get_queryset().filter(
animal_id=self.kwargs['pk']
)
0
You can use lookup_field
:
class MyAnimalSex(generics.RetrieveAPIView):
queryset = AnimalSex.objects.all()
serializer_class = AnimalSexSerializer
lookup_field = 'animal'
- [Django]-Django CBV DetailView – accessing the object to assign to a context variable?
- [Django]-Django – how to duplicate all fields definitions from one model to another without inheritance
- [Django]-How can i create Generated/Computed column Postgres/DJANGO?
Source:stackexchange.com