I want to update my model instance using .update(**kwargs)
for non-realted fields and .clear()
followed by .add()
for related fields. My problem is that only one of them is getting executed at a time.
When I do the following its working and updating the m2m fields:
def preview(request):
worksheet_object = WorkSheet.objects.get(pk=int(wsheet_id))
worksheet_object.question.clear()
worksheet_object.question.add(*question_pk_list)
#other m2m fields
But I want to update the non-related fields also and its not working when I do the following:
def preview(request):
worksheet_object = WorkSheet.objects.get(pk=int(wsheet_id)).update(
classroom=worksheet_data['classroom'],
category=worksheet_data['category'],
#other fields)
worksheet_object.question.clear()
worksheet_object.question.add(*question_pk_list)
#other m2m fields
I am using this answer and this answer to do the same in my view.
Can anyone help figure out what I am doing wrong? and how it can be corrected?