1👍
✅
You need to link the seed_related
to the Seed
you construct through the form:
def seed_create(request):
if request.method == 'POST':
seed_form = SeedForm(request.POST, request.FILES)
docu_form = DocumentForm(request.POST, request.FILES)
if seed_form.is_valid() and docu_form.is_valid():
seed_form.instance.user = request.user
seed = seed_form.save()
docu_form.instance.seed_related = seed
docu_form.save()
messages.success(request, 'Your seed was successfully created!')
return redirect('seed:view_seed')
else:
messages.error(request, 'Please correct the error below.')
else:
seed_form = SeedForm()
docu_form = DocumentForm()
return render(
request,
'seed/create.html',
context={'seed_form': seed_form, 'docu_form': docu_form}
)
Source:stackexchange.com