I'll try to sum up with a brief description of the logic. I have 2 models (I'm using django smart_selects too): One "actuacion" can be related with a previous actuacion and in that case they will have the same number of "parcelas" related.
from smart_selects.db_fields import ChainedForeignKey
class Actuacion(models.Model):
[...]
parcelas = models.ManyToManyField('Parcela', related_name="actuaciones", blank=True)
actuacion_precedente = ChainedForeignKey(
'self', on_delete=models.CASCADE, null=True, blank=True,
chained_field="paraje", chained_model_field="paraje")
class Parcela(models.Model):
[...]
In the admin I have:
class ActuacionAdmin(admin.ModelAdmin):
[...]
filter_horizontal = ('parcelas', )
After populating my database I take this output: (the first number is the ID of the object "parcela").
What the hell is going on? Reading directly the database gives me 5 objects properly. However the front-end is duplicating the information.
I've tested and played linking the first actuacion to a second one linked to a third one and the results appears thrice. (and with 4, 5... the same).
Any idea will be tested and appreciated.
Thanks for your help. Pablo :)
