Reputation: 61
please help to solve the problem.
I created a form to register users. I need the user to have access after registration adminpanel. for this I have tried to override the value of the field is_staff:
class RegistrationForm(UserCreationForm):
is_staff = forms.CharField(
default=True,
widget=forms.HiddenInput(),
)
class Meta:
model = User
fields = (
'username',
'email',
'password1',
'password2',
'is_staff',
)
views:
def registration(request):
"""
ajax refistration procedure
"""
result = False
form = RegistrationForm()
if request.method == 'POST' and request.is_ajax():
form = RegistrationForm(request.POST)
if form.is_valid():
try:
new_user = form.save()
except:
pass
else:
result = True
data = {
'result': result,
}
return HttpResponse(json.dumps(data), content_type='application/json')
the problem is that the browser displays the following error message:
TypeError at /
__init__() got an unexpected keyword argument 'default' Request Method: GET Request URL: Django Version: 1.6.8
Exception Type: TypeError Exception Value:
__init__() got an unexpected keyword argument 'default' Exception Location: /home/kalinins/.virtualenvs/kinopom_project/kinopom_env/local/lib/python2.7/site-packages/django/forms/fields.py
in __init__, line 198
Upvotes: 0
Views: 52
Reputation: 122336
The error you're getting means the keyword argument default=True
is incorrect when creating the is_staff
field.
You should be using initial=True
instead to specify an initial value.
Furthermore, you are using a forms.CharField
for the is_staff
field, which presumably should be a boolean (so forms.BooleanField
). After that it'll be displayed as a tick box and not as a field for text characters.
Upvotes: 2