I am trying to learn Django so I am pretty much a noob.
I have been trying to do the following simple task for two hours now. I know I have the wrong syntax, but searching Google & SO has not helped me, so I need some advice.
I am trying to update a db field from a Django template, but I need help in understanding how to update the language_code_disabled in my LanguageVersions views.py code below.
Here is my models.py file code:
"""Language version selection for a user"""
user = models.ForeignKey(User)
language_code = models.CharField(max_length=32)
language_code_disabled = models.BooleanField(default=False)
Here is my views.py code:
if request.method == 'POST':
language_version = LanguageVersion.objects.get(pk=language_version_id, user=request.user)
# don't enable Language Version for currently selected language preference.
if language_version.language_code != request.user.userprofile.language_preference:
if language_version.language_code_disabled == True:
# if the users Language Version is disabled, enable the disabled Language Version.
LanguageVersion.language_code_disabled = False # THIS IS THE LINE OF CODE I DO NOT UNDERSTAND HOW TO WRITE!
Excuse the simple question, but I am unable to get this correct.
You need to update field in the instance (not in the class) and call
save() method of this instance.
language_version.language_code_disabled = False language_version.save()