I have three models:
class Member(models.Model):
person_id = models.CharField(max_length=100, null=True)
first_name = models.CharField(max_length=100, null=True)
last_name = models.CharField(max_length=100, null=True)
minit = models.CharField(max_length=1, null=True)
dob = models.DateField(null=True)
class Project(models.Model):
project_name = models.CharField(max_length=100)
project_description = models.CharField(max_length=100)
project_owner = models.CharField(max_length=100)
dos_from = models.DateField()
dos_to = models.DateField()
class Review(models.Model):
member = models.ForeignKey(Member, on_delete=models.CASCADE, related_name='review_rel')
project = models.ForeignKey(Project, on_delete=models.CASCADE)
dos= models.DateField()
review_type= models.CharField(max_length=25)
Some members will have no reviews at all, some will have multiple reviews even within the same project.
I would like to create a table with one row per member and project for the members who are assigned a review.
When I start with the Review model, I get multiple rows for the same member (if the member has more than one review within the same project) I don’t know how to dedup it.
import django_tables2 as tables
class Reviews_Table(tables.Table):
class Meta:
model = Review
fields = (
"project__project_name",
"member__person_id",
"member__first_name",
"member__last_name",
"member__minit",
"member__dob",
)
I also tried starting with the Member Model, but I can’t figure out how to go backwards and link to the Review model.
I have been stuck on this for a while. I would truly appreciate help.
Thank you