Answer the question
In order to leave comments, you need to log in
How to handle multiple forms on one page?
Hello, I want to group forms on one page in tabs.
For example, here are the forms
class FarmEditContact(forms.ModelForm):
class Meta:
model = Ranch
fields = ('address','coord','phone1','phone2','worktime', 'vk', 'fb','insta','ok')
class FarmEditOffers(forms.ModelForm):
class Meta:
model = Ranch
fields = ('offer1', 'price1', 'offer2', 'price2', 'offer3', 'price3')
def farm_edit(request, id):
farm = get_object_or_404(Ranch, id=id)
if request.method == "POST":
form1 = FarmEditMain(request.POST, instance=farm)
if form.is_valid():
farm = form.save(commit=False)
farm.owner = request.user
farm.published_date = timezone.now()
farm.save()
return redirect('ranch.views.own_farm_detail', id=farm.id)
else:
form = FarmEditForm(instance=farm)
return render(request, 'farms/farm_edit.html', {'form': form}
Answer the question
In order to leave comments, you need to log in
Either this https://docs.djangoproject.com/ja/1.9/ref/forms/ap...
Or you can initialize both forms directly in the code (because your field sets do not match, and required=False does not, then there should be no ambiguities) and check for validity first the first, then the second.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question