Search code examples
djangodjango-users

How to know which user added another user?


How do I know which user added another user?

User A registers and is assigned admin status. User A adds User B within the application. How can I save User A in my extended user model so I know who has added who? This is a multi-tenant application. Django/Postgres


Solution

  • Added this to view for adding new users from within application.

    if form.is_valid():
    obj = form.save()
    obj.profile.admin_id = request.user.id
    obj.profile.save()
    return redirect(‘dashboard’)
    

    Thank you to Lúcio Henrique.

    https://community.simpleisbetterthancomplex.com/t/add-users-within-application-and-save-who-added-them-in-extended-model/751/5