Hi
I have a two models, Model1 and Model2.
Model2 has a FK to Model1 and FK to iteself.
In the admin I show Model2 as inlines in Model1 change_form.
I want to modify the way the inlines are shown in the admin.
I need to group all the instances that have the same parent_model2 and display them as
a readonly field with a string of 'childs' in the parent Model2 instance.
I know how to use itertools.groupby (or the django version) but don't know how to do it in the admin.
What should I override to be able to iterate over all the Model2 instances, group them by parent, add children to the parent and remove children from the inlines?
class Model1(models.Model):
name = models.CharField()
class Model2(models.Model):
name = models.CharField()
fk_model1 = models.ForeignKey('self', blank=True, null=True)
parent_model2 = models.ForeignKey('self', blank=True, null=True)
Thanks