I have to change the “is_staff” option from views.py file to disabling the Django-admin page but i am not able to figure out this following issue.
Whenever i tried to write “user.is_staff” then it sound that there is not any option to choose it (is_staff) whereas is_active is present. is this problem of importing?
Following are the content which i am importing:
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib.auth.models import User
from django.http import HttpResponseForbidden, HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic.list_detail import object_detail
from django.views.generic.simple import direct_to_template
from django.utils.translation import ugettext as _
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
Following code i wrote in views.py:
def user_change_status(request, id):
user = User.objects.get(pk=id)
if user.is_staff:
user.is_staff = False
else:
user.is_active = True
return HttpResponse('')
Whole scenario is that i have a template which is showing the list of all user with his/her is_staff option (True/ False). What i want when superuser will select any of user is_staff option it become change and the page will redirect on the same page.
After editing:
Two method are defined in views.py:
def user_change_status(request, id):
user = User.objects.get(pk=id)
if user.is_active:
user.is_staff = False
else:
user.is_staff = True
user.save()
value2 = user.is_staff
return HttpResponse(value2)
and another one is `
def user_block(request, id):
user = User.objects.get(pk=id)
if user.is_active:
user.is_active = False
else:
user.is_active = True
user.save()
value1 = user.is_active
return HttpResponse('value1')
I want to change the is_staff value and is_active value. Method user_change_status is not working whereas user_block does.
Python is a dynamic language. In particular, it’s not Java or C++. As a rule, IDEs do very badly in autocompleting in dynamic languages.
It’s a complete mistake to take any notice of what your IDE does or doesn’t offer as autocomplete options. Sometimes it’ll get it right, other times it won’t. Sometimes it’ll offer options that aren’t members of the object at all.
Use the documentation, not your IDE.