Set different value for a field when Admin creates an user

11 views
Skip to first unread message

Fruity Code

unread,
Nov 29, 2019, 7:42:00 AM11/29/19
to Django users
I have an updated user model and added two fields to it, mobile_number and role. The field role has two options Customer and Admin. Currently, I have made customer as the default value for role. Now what I want is when user signup the role should be a customer but when an admin create a user from Django admin it's role should be Admin.

Sencer Hamarat

unread,
Nov 29, 2019, 8:36:09 AM11/29/19
to django...@googlegroups.com
Check request.user.is_superuser. If it return True, the role of the user signed in is Admin.

Saygılarımla,
Sencer HAMARAT



On Fri, Nov 29, 2019 at 3:41 PM Fruity Code <abhaya...@gmail.com> wrote:
I have an updated user model and added two fields to it, mobile_number and role. The field role has two options Customer and Admin. Currently, I have made customer as the default value for role. Now what I want is when user signup the role should be a customer but when an admin create a user from Django admin it's role should be Admin.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/02a95589-3cae-4731-9a1a-66872d630e68%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages