python - Django .is_superuser field permission -


by default project directory running manage.py createsuperuser command able create superuser, .is_superuser flag default django flag differ superuser or other user.

i don't want use because using flag throughout application show settings menu. instead, added field in userprofile models, field .is_primary_user.

is there way control that, if run createsuperuser comment, should update .is_primary_user field "1" in userprofile model?

yes there is, have catch signal of post_save of user model, , if .is_superuser changed, change .is_primary_user.

has brian neal pointed out, should not use .is_superuser flag in application. meant used along django permission system (a superuser has permissions everything) and/or django admin.

edit: haven't tested, should this:

from django.db.models.signals import pre_save django.contrib.auth import user  # method updating def update_primary_user(sender, instance, **kwargs):      if instance.pk:           return      if instance.is_superuser , not instance.userprofile.is_primary_user:           instance.userprofile.is_primary_user = true           instance.userprofile.save()  # register signal pre_save.connect(update_primary_user, sender=user) 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -