2👍
Based on comments, if your Entry
model has a foreign key to User
, you don’t need to use threadlocals in order to get all of the information about a user after an instance of the model is saved or deleted.
The Signals sub-framework will give you the abilities you’re looking for. For example, pre_delete
could be used to send an email out before the object is deleted. post_save
could be sent after an entry is created or updated.
The signal handler will receive an instance of the object that triggered the signal, and you’ll be able to access the user object, including all of it’s properties to send your email out. Although only the id of the User is stored in the database, Django will give you access to the complete object through the ForeignKey field.
[EDIT]
To get the object instance in the signal handler, retrieve it from the kwargs passed to the handler:
def my_callback(sender, **kwargs):
instance = kwargs.get('instance')
# you can now reference instance.user
# send email code here