I have a modelform and aside from the fields on the form i need to update one more column in the database depending on if there is a registered user submitting information or not. I read that you can use the save method with the argument "commit=False" which will create the database object but not save it to the database so i can check if the user is logged in and then also save additional information if i need to, and then call save myself. Does this seem like a reasonable approach to solve this problem ?
Yes, that is exactly the right thing to do.
if form.is_valid():
object = form.save(commit=False)
if request.user.is_authenticated():
object.user = request.user
object.save()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments