简体   繁体   中英

How to display all the users created by a particular user in django?

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?

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, ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM