1👍
✅
You are saving q
before c
. But as q
has field (foreignkey) for c
, c
needs to be saved first. Django internally refers id of c
to update the tables and rows appropriately.
So change your code to
c = f.save(commit=False)
# c.pub_date = timezone.now()
c.save() #save c
#prepare object
q = Question()
q.question_text = c
q.project = a
q.user = request.user
q.save()
Source:stackexchange.com