Since django does not support symmetrical many-to-many relationships with additional data, you probably need to force this yourself.
If you have a convenient, immutable value in the system (for example, the system identifier), you can create a predictable algorithm for which the system will be stored in a record in your table. If, at the time of creation of the System Interface object, they are always saved, you can use the primary key.
Then write a function to create the interface. For instance:
class System(models.Model): def addInterface(self, other_system, user): system_interface = SystemInterface() system_interface.assigned_to = user if other_system.id < self.id: system_interface.first_system = other_system system_interface.second_system = self else: system_interface.first_system = self system_interface.second_system = other_system system_interface.save() return system_interface
Using this construct, you can perform a routine check, duplication detection, etc. on the SystemInterface object. The main thing is that you apply the restriction in your code, not in the data model.
It makes sense?
cwied source share