class Institution(models.Model):
name = models.CharField(max_length=300)
class StudentGroup(models.Model):
institution = models.ForeignKey(Institution)
name = models.CharField(max_length=50)
students = models.ManyToManyField(
'Student',
related_name='studentgroups',
)
class Student(models.Model):
first_name = models.CharField(max_length=50, blank=True, null=True)
When I hit /institutions/id/studentgroups/id/students/, it returns duplicate entries, which is an expected behavior as far as Django is concerned. However, that's not what the user expects as the response. To make it distinct, I had to do the following workaround on my StudentViewSet:
Since the queries are being handles by the NestedViewSetMixin, I think it should have some way of specifying a .distinct()? Or is this better handled somewhere else?
Following 3 models:
My nested routes are as follows:
When I hit
/institutions/id/studentgroups/id/students/
, it returns duplicate entries, which is an expected behavior as far as Django is concerned. However, that's not what the user expects as the response. To make it distinct, I had to do the following workaround on my StudentViewSet:Since the queries are being handles by the NestedViewSetMixin, I think it should have some way of specifying a
.distinct()
? Or is this better handled somewhere else?