Reputation: 503
Is it possible to access the current session in the user model .save()?
pseudo code of what I want to achieve:
# users.models.py
def save(self, *args, **kwargs):
created = True
if self.pk:
created = False
super(AbstractUser, self).save(*args, **kwargs)
# post-save
if created:
look_for_invite_in_session_and_register_if_found(self, session)
Upvotes: 0
Views: 364
Reputation: 10145
Seems it something wrong in your architecture. You shouldn't access request in models layer. All work with request must be done in view. You can do it like this:
user, created = AbstractUser.objects.get_or_create(name=name)
if created:
look_for_invite_in_session_and_register_if_found(user, request.session)
Upvotes: 1