November 2015
Beginner to intermediate
840 pages
26h 30m
English
An admin action is a method that changes one or more objects. For instance, it may be useful to be able to select multiple users and change their is_staff field to True, to allow them access to the admin site. This counts as an action.
Thanks to the ORM, given a queryset from the User model with multiple User instances, we can simply use the update() method to change the information on all of those User objects. The qs.update(is_staff=True) will update all of the User instances selected by the queryset to be True. To disable every User from having access, we could use the code shown in Example 23.51.
Example 23.51: Python Code
User.objects.all().update(is_staff=False) # the all() is ...
Read now
Unlock full access