i want to save is_staff value true in db but not save in database

106 views
Skip to first unread message

lalitaquasoft

unread,
Aug 1, 2018, 4:06:20 AM8/1/18
to Django users
Advance Thanks for your help:

is_staff  value is not save in database

Here is Code:

from django.contrib.auth import login, authenticate
from django.shortcuts import render, redirect
from blog.forms import SignUpForm 

def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
        form.is_staff = 1
        form.save()
            # username = form.cleaned_data.get('username')
            # raw_password = form.cleaned_data.get('password1')
            # user = authenticate(username=username, password=raw_password)
            # login(request, user)
            # return redirect('home')
    else:
        form = SignUpForm()
    return render(request, 'register.html', {'form': form})

mazz ahmed

unread,
Aug 1, 2018, 7:18:14 AM8/1/18
to django...@googlegroups.com
set is_staff to true to Account model in django model after that save method will be called

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54a3c692-3232-4032-aadd-561789b92c91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lalit Kumar

unread,
Aug 2, 2018, 2:18:02 AM8/2/18
to django...@googlegroups.com
Thanks Sir for your guidance , but i have many option is_staff  , is_user , i have to save it from view views , any other way to save it from views

Matthew Pava

unread,
Aug 2, 2018, 9:41:26 AM8/2/18
to django...@googlegroups.com

You’re adding an attribute (is_staff) to the form and then saving the form, but no method is doing anything with that attribute.

When you save a model form, it will return the instance of the model.  You can then proceed to change that model, and save it again.

 

        if form.is_valid():

           instance = form.save(commit=False)  # get the model instance from the filled-out form without saving it to the database

           instance.is_staff = True  # modify the instance by changing the is_staff attribute to True

     instance.save()  # save the instance of the model to the database

     form.save_m2m()  # for handling any many-to-many relationships that are not saved when commit=False

 

Please review the documentation:

https://docs.djangoproject.com/en/2.0/topics/forms/modelforms/

--

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

 

--

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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Lalit Kumar

unread,
Aug 4, 2018, 3:47:22 AM8/4/18
to django...@googlegroups.com
Thanks Sir   this work 

--

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.


To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages