Consider this model (simplified for this question):
class SecretAgentName(models.Model):
name = models.CharField(max_length=100)
aliases = ManyToManyField('self')
I have three names, "James Bond", "007" and "Jason Bourne". "James Bond" and "007" are aliases of each other.
This works exactly like I want it to, except for the fact that every instance can also be an alias of itself. This I want to prevent. So, there can be many SecretAgentNames, all can be aliases of each other as long as "James Bond" does not show up as an alias for "James Bond".
Can I prevent this in the model definition? If not, can I prevent it anywhere else, preferably so that the Django Admin understands it?
I think you’re ERD is off here. I would sugest Secret Agent Name as a parent of Aliasses, and store all names in Alliasses, leaving only meta in Secret Agent Names. Then all you need is a many-to-one relationship from Alliasses to Secret Agent Names.