Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: issues rendering form and submitting with ModelForm
    text
    copied!<p>I'm trying to create a form that lets users add Notes to objects. It's similiar to the django comment package but I have not been able to get that to work (the tutorial in django documentation isn't working). </p> <p>Here is my model and ModelForm:</p> <pre><code>class Note(models.Model): text = models.CharField(max_length = 200) thing_about = generic.GenericForeignKey('content_type','object_id') content_type = models.ForeignKey(ContentType, limit_choices_to={"model__in": ("Individual", "ArtsOrganization",'Presenter', "BookingAgent","Festival","ManagementCompany", "OtherOrganization","PresenterCompany", "Venue", "Gig", "Venue")},blank=True, null=True) object_id = models.IntegerField(db_index=True, blank=True, null=True,) date_added = models.DateTimeField(('date added'), auto_now_add=True) date_modified = models.DateTimeField(('date modified'), auto_now=True) author = models.ForeignKey(User) def __unicode__(self): return u'%s' % (self.date_added) class NoteForm(ModelForm): class Meta: model = Note </code></pre> <p>My views.py</p> <pre><code>def note(request): if request.method == 'POST': # If the form has been submitted... form = NoteForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data form.save() return HttpResponseRedirect('/thanks/') # Redirect after POST else: form = NoteForm() # An unbound form return render(request, 'includes/note.html', { 'form': form, }) </code></pre> <p>I have created a template under myapp/templates/includes/note.html so that I can use the form for each object (which all have different detail pages) i.e. make a note on the Band page and the Venue page using the same form.</p> <p>Here is the contents of the template 'includes/notes.html':</p> <pre><code>&lt;form action="includes/note/" method="post"&gt;{% csrf_token %} {{ form.as_p }} &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>The problem is that the form does not render. I'm not sure if the view is reaching the template so that it even knows what form to render. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload