21
Nov
11

always specify fields for django’s ModelForm as a tuple



So, I had a model that had a FileField called path, for which I wanted a ModelForm. Do not do this:


class MyModelForm(ModelForm):
   class Meta:
      model = MyModel
      fields= ("path")

It led to a strange error, saying django.core.exceptions.FieldError: Unknown field(s) (a, p, t, h). Of course, the fix was to specify the fields like:


class MyModelForm(ModelForm):
   class Meta:
      model = MyModel
      fields= ("path",)

Advertisements

0 Responses to “always specify fields for django’s ModelForm as a tuple”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 223,857 hits

%d bloggers like this: