Skip to content
Advertisement

How to create a form that make user is_active = False?

In my Django project, there are several types of users. User types are lead, manager, analyst. The Leads should change every user’s is_active attribute. I created a form and view for that. I have a users page and every user is listing here with a for loop.

What I want is lead can block a user with is_active = False method. But my form is does not work because I think I cannot reach the user. How can I solve it?

views.py

JavaScript

def users(request):

JavaScript

forms.py

JavaScript

models.py

JavaScript

traceback

JavaScript

Advertisement

Answer

You can use forms.ModelChoiceField(Dango Docs) in the MakeInactive form. Also instead forms.ModelForm use forms.Form.

Then the UserProfile with rank lead can select a UserProfile with rank manager or analyst and set it inactive.

You can add the current user to MakeInactive form and filter the UserProfile in the __init__ method.

You cat try to use the below code:

forms.py:

JavaScript

views.py:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement