I want to create a model, which is symmetric on two fields. Let's call the model Balance:
class Balance (models.Model):
payer = models.ForeignKey(auth.User, ...)
payee = models.ForeignKey(auth.User, ...)
amount = models.DecimalField(...)
It should have the following property:
balance_forward = Balance.objects.get(payer=USER_1, payee=USER_2)
balance_backward = Balance.objects.get(payer=USER_2, payee=USER_1)
balance_forward.amount == -1 * balance_backward.amount
What is the best way to implement this?
So, I came up with the following solution. Feel free to suggest other solutions.