0

I'm having a weird issue when using a ModelForm as a form_class for UpdateView.

First of all: When using the UpdateView without the form_class tag, everything works perfectly. However, when I try to use the ModelForm (because I want to add a MarkdownField) I get <mediwiki.views.MediwikiForm object at 0x7f990dfce080>displayed in my browser window. Just in plain text?

#template/mediwiki/create2.html:
<form action="" method="post">{% csrf_token %}
    {{ form }}
        <input type="submit" value="Save" />
</form>

#views.py:
class EntryUpdate(UpdateView):
    model = Mediwiki
    slug_field = 'non_proprietary_name'
    template_name = "mediwiki/create2.html"
    form_class = MediwikiForm⋅
    #fields = '__all__' #this works...

#forms.py
class MediwikiForm(ModelForm):
#    wiki_page_markdown = MarkdownxFormField()
    class Meta:
        model = Mediwiki⋅
        fields = ['non_proprietary_name', 'category', 'wiki_page_markdown']

#models.py
class Mediwiki(models.Model):
    non_proprietary_name = models.CharField(max_length = 100, unique = True)
    category = models.ManyToManyField(Category)
    wiki_page = models.TextField(blank = True)
    wiki_page_markdown = models.TextField(blank = True)

    def save(self):
        import markdown
        self.wiki_page = markdown.markdown(self.wiki_page_markdown)
        super(Mediwiki, self).save() # Call the "real" save() method.

    def get_absolute_url(self): # For redirect after UpdateView
        return reverse('entry', kwargs={'slug': self.non_proprietary_name})

    def __str__(self):
        return self.non_proprietary_name

#urls.py
url(r'^mediwiki/(?P<slug>\D+)/edit$', EntryUpdate.as_view(), name="update"),

Any idea what might cause this error? Any help will be much appreciated...

theCed7
  • 125
  • 3
  • 15
  • It's probably a cut-and-paste issue but what are the weird blobs after the form_class definition in the view and the model definition in the form? – Daniel Roseman Aug 18 '16 at 15:36
  • @DanielRoseman Yes, that's most likely from copy-pasting and the auto-indent feature of my VIM config. – theCed7 Aug 18 '16 at 15:39
  • Could you possibly have another thing defined in your views.py with the name MediwikiForm? I'm intrigued by the fact that it says `mediwiki.views.MediwikiForm object` rather than `mediwiki.forms...`. – Daniel Roseman Aug 18 '16 at 15:55
  • @DanielRoseman Ahhh! Good catch! Called the `CreateView` which also uses `MediwikiForm` `class MediwikiForm (CreateView)`. Very clever indeed. Thank you so much! Would've taken me years to figure that out! – theCed7 Aug 18 '16 at 16:43

0 Answers0