samedi 11 novembre 2017

Django gets all checkboxes values, checked or un-checked

Using Django's User model, I have the following template:



which shows the status of each account and the user may update them.

In the views:

accounts = request.POST.getlist('account')    # This will get only the `checked` ones
for account in User.objects.filter(id__in=accounts):
    if account is checked:    # Only hypothetical ...
        account.is_active = True
    else:
        account.is_active = False
    account.save()

Questions:

  1. How do I retrieve ALL checkboxes, checked or un-checked?

  2. How can the retrieved list contains the status of each account, so that I can set the account's is_active field accordingly?




Aucun commentaire:

Enregistrer un commentaire