1👍
✅
Not that it will necessarily solve your problem, but the Django way to get a single record is Queryset.get
try:
u=User.objects.get(username=username)
except User.DoesNotExist:
raise Http404()
u.is_staff=True;
u.save() #
print u, u.is_staff
Also your view should only accept POST requests.
0👍
Can’t you just do a
User.objects.filter(username=username).update(is_staff=True)
It will update the data (without having to call save()) for every object the filter finds.
- [Answer]-Django + Extjs 5.1.1
- [Answer]-Stale content type prompt deleting all model instances after renaming django model with permissions
- [Answer]-AttributeError when establishing a foreign key using the to_field option
- [Answer]-How can I reuse django form for searching?
Source:stackexchange.com