- [Django]-Check for pending Django migrations
- [Django]-Manage.py runserver
- [Django]-In django do models have a default timestamp field?
- [Django]-Unable to perform collectstatic
- [Django]-Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet
- [Django]-How to run own daemon processes with Django?
10👍
Another (less concise readable, more arithmetic) way to do it would be:
item.active = bool(1 - item.active)
👤miku
- [Django]-"Too many values to unpack" Exception
- [Django]-Where does pip install its packages?
- [Django]-What is a "django backend"?
7👍
The negation for booleans is not
.
def toggle_active(item_id):
item = Item.objects.get(id=item_id)
item.active = not item.active
item.save()
Thanks guys, that was a lightning fast response!
- [Django]-Why there are two process when i run python manage.py runserver
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
- [Django]-AWS: can't connect to RDS database from my machine
5👍
Its simple to do :
item.active = not item.active
So, finally you will end up with :
def toggleActive(item_id):
item = Item.objects.get(id=item_id)
item.active = not item.active
item.save()
- [Django]-CORS error while consuming calling REST API with React
- [Django]-Django Rest Framework remove csrf
- [Django]-Reducing Django Memory Usage. Low hanging fruit?
Source:stackexchange.com