Reputation:
For example: if a user creates n number of users . I want to display the n number of users created by that particular user alone in django .
I can't come up with a solution.
Do i have to create a model like profile with OnetoOnemodel of user?
Upvotes: 0
Views: 34
Reputation: 824
It's a fair question, but no, you can't guarantee knowledge of who created the user. Users just exist in a database and thus can be created completed outside of Django. What you could do is create a UserAdmin
and overwrite save_model
to set some field, i.e, creator
, as the current user:
# set creator as logged-in user
def save_model(self, request, obj, form, change):
obj.creator = request.user
super(MyUserAdmin, self).save_model(request, obj, form, change)
But this still does not guarantee an audit of any user; only those created through the admin. See the docs for more on admin methods.
Upvotes: 1