Thank you very much for the help Matthew, that is absolutely spot on, and greatly appreciated.
My view now looks like this: def builddetails(request, id): if request.method == 'POST': form = BuildForm(request.POST or None) if form.is_valid(): form.save() return HttpResponseRedirect('/builds') else: form = BuildForm() build = Build.objects.get(pk=id) return render(request, 'app/builddetails.html', { 'build': build, 'form': form }) It appears to be working, but I get an error when saving the form: IntegrityError at /builds/8 NOT NULL constraint failed: app_build.requested_by_id I want to use this form to update records in the database - do I need to do something special in the view so that it knows which record to update? Thanks again, Mark On Friday, June 16, 2017 at 2:27:31 PM UTC+1, Matthew Pava wrote: > > Hi Mark, > > You would pass the form in the context of the template in the view. You > can pass pretty much anything to a template through the context. > > > > def builddetails(request, id): > > build = Build.objects.get(pk=id) > > form = BuildForm(request.POST or None) > > if form.is_valid(): > > form.save() > > return render(request, 'app/builddetails.html', { 'build': build, > ‘form’: form }) > > > > > > > > *From:* django...@googlegroups.com <javascript:> [mailto: > django...@googlegroups.com <javascript:>] *On Behalf Of *Mark Alan Jones > *Sent:* Thursday, June 15, 2017 6:04 PM > *To:* Django users > *Subject:* how to combine views in one template > > > > Hello Django Community, > > I am new to Django and tackling my first app outside of the tutorial. The > app I'm working on is a simple ticket system for build requests at my IT > Company. I only have one model 'Build', and I have checkboxes that denote > how far the build has been done. > > > > I have a page that shows all build requests, and then a separate page with > the details of each build request. I want to add a form to this > builddetails template, but I'm not sure what is the correct way to do this > when the template is already pulling info from the model. Every tutorial > I've followed has shown using a form under a separate URL, but that is not > viable. > > > > my current view for builddetails is this: > > > > def builddetails(request, id): > > build = Build.objects.get(pk=id); > > return render(request, 'app/builddetails.html', { 'build': build }); > > > > How do I combine this with a ModelForm on the same page? > > > > the ModelForm I was trying to use looks like this: > > > > class BuildForm(forms.ModelForm): > > class Meta: > > model = Build, > > fields = ['notes', 'build_engineer', > 'latest_bios','bios_settings', 'hot_keys_tested', 'office_activated'] > > > If I need to provide any more information please let me know, and thank > you so much in advance for any help you can offer. > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users...@googlegroups.com <javascript:>. > To post to this group, send email to djang...@googlegroups.com > <javascript:>. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/733168e2-2559-4726-9067-dc2a23397bb7%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/733168e2-2559-4726-9067-dc2a23397bb7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f6a37655-87e2-45f2-ad3a-3b1280d19357%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.