I have my parishioner model like below (Only pasting relevant CODE)
class Parishioner(models.Model):
family = models.ForeignKey(Family, null=True, on_delete=models.PROTECT, related_name='members')
role = models.ForeignKey(FamilyRole, null=True, blank=True, on_delete=models.PROTECT, related_name='role')
Parishioner can have one Family and One role in that family
So I'm trying to achieve this in my Family Serializer.
class FamilySerializer(serializers.ModelSerializer):
members = serializers.PrimaryKeyRelatedField(
many=True,
queryset=Parishioner.objects.all(),
allow_null=True,
required=False
)
class Meta:
model = Family
fields = ('id', 'name', 'address', 'monthly_contribution', 'members', 'enabled')
read_only_fields = ('id',)
depth = 1
As you can see above I can clearly assign members to that Family.
But I want to assign roles to Each family member as well. How can I do that in Django ?
Examples for FamilyRole: Father, Mother, son, daughter
My front end will be similar to this in my Create Family page (and I expect to send only one request to server to achieve this by using api/family/ endpoint)
Simply I want to,
Create a Family,
Assign Members(Parishioners) to that Family,
Assign Role to each of those Member(Parishioner),
Through api/family/ endpoint.
What is the best way to achieve above ?
