python - Logical NOT operation in django -


i have view function toggles user state (active-inactive):

def toggle_user_state(request, user_id, current_state):     user = get_object_or_404(user, pk=user_id)     user.is_active = not current_state     user.save()     return httpresponseredirect(reverse('cdms:user_details', kwargs={'user_id': user.id})) 

if current_state true, works making false. if current_state false, remains false.

i have tried print(not current_state), surprisingly not false remains false!

i not sure why need current_state when can toggle is_active on user:

def toggle_user_state(request, user_id):     user = get_object_or_404(user, pk=user_id)     user.is_active = not user.is_active    # take not of active state here     user.save()     return httpresponseredirect(reverse('cdms:user_details', kwargs={'user_id': user.id})) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -