Abhishek
Abhishek

Reputation: 3068

Django update user is_active to True in a view

I have a django view as follows:

@staff_member_required
def approve(request, pk):

    prnt = Parent.objects.get(id=pk)
    prnt.request_status = 'A'
    prnt.user.is_active = True

    prnt.save()

The view updates every field except the is_active field. Here User has OneToOne relationship with the Parent model. Where is the issue? the console doesn't throw any errors either.

Upvotes: 0

Views: 2227

Answers (1)

Aamir Rind
Aamir Rind

Reputation: 39679

You need to save the user object manually:

prnt = Parent.objects.get(id=pk)
prnt.request_status = 'A'
prnt.user.is_active = True
prnt.user.save()  # <---- here
prnt.save()

Upvotes: 4

Related Questions