I have a Django class
class Chat(models.Model):
primary_node = models.ForeignKey('nodes.Node', blank=True, null=True, related_name='chats_at_this_pri_node', on_delete=models.SET_NULL)
secondary_node = models.ForeignKey('nodes.Node', blank=True, null=True, related_name='chats_at_this_sec_node', on_delete=models.SET_NULL)
I want to forbid direct assigning of fields, such as
chat.primary_node = some_node
and instead create a method chat.assign_node(primary, secondary)
that updates nodes via Django Chat.update()
model method.
The reason is that I want to log all changes to these nodes (count changes and update other model fields with the new count), but dont want myself and other developers to forget that we cannot assign fields directly, as this wouldn't trigger custom assign_node
logic.
How сan I do that?