I’ve got a model called EventMembership which determines whether someone is attending the event or not:-
class EventMembership(models.Model):
user = models.ForeignKey(User, related_name='eventmemberships')
is_attending = models.BooleanField()
I also have an EventFee model which is used to track the user’s fees for events:-
class EventFee(models.Model):
user = models.ForeignKey(User, related_name='eventfees')
amount = models.DecimalField()
If a user is attending the event, they should have a fee for that event’s price. If not, they should not have a fee.
What is the best way for me to handle the creating, updating or deleting of these fees?
I’ve seen a lot of people warn against using signals and I have had problems with signals in the past but they seem like the perfect solution.
I suppose it’s signals or override the save() method on the model, isn’t it? But overriding the save() method would mean the fees get updated every time the model is saved which seems bad to me.
Any other suggestions?
Note: I’m using Django Rest Framework for this so these EventMemberships can be created, updated or deleted through that. But they can also be updated via a couple of other mechanisms, like a user deleting their account, for example – where all of their memberships for future events will be set to “not attending” so I’m not sure I should do the fee creation etc. in a serializer or a view.