69π
Like the error mentions, you need to explicitly specify the fields, or exclude.
Try this
class JobForm(models.ModelForm):
#fields
class Meta:
model = Job
fields = "__all__"
which would include all the fields
Here is the relevant documentation (release notes 1.6)
Previously, if you wanted a ModelForm to use all fields on the model,
you could simply omit the Meta.fields attribute, and all fields would
be used.This can lead to security problems where fields are added to the model
and, unintentionally, automatically become editable by end users. In
some cases, particular with boolean fields, it is possible for this
problem to be completely invisible. This is a form of Mass assignment
vulnerability.For this reason, this behavior is deprecated, and using the
Meta.exclude option is strongly discouraged. Instead, all fields that
are intended for inclusion in the form should be listed explicitly in
the fields attribute.If this security concern really does not apply in your case, there is
a shortcut to explicitly indicate that all fields should be used β use
the special value β__all__
β for the fields attribute
5π
You can set fields or exclude in the ModelForm in Django 1.7.
It changes in 1.8, you should set fields or exclude in the Meta class within ModelForm.
class JobForm(models.ModelForm):
#fields
class Meta:
model = Job
fields = "__all__"
- Django ForeignKey limit_choices_to a different ForeignKey id
- Problem launching docker-compose : python modules not installed
- Select Children of an Object With ForeignKey in Django?
- Gunicorn sync workers spawning processes
0π
I got the same error when I set "Meta" inner class without "fields" or "exclude" attributes in "NewUserForm(UserCreationForm)" class in "account/forms.py" to create a form as shown below:
# "account/forms.py"
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class NewUserForm(UserCreationForm):
class Meta: # Here
model = User
So, I added "fields" attribute to "Meta" inner class as shown below:
# "account/forms.py"
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class NewUserForm(UserCreationForm):
class Meta: # Here
model = User
fields = ("username",) # Here
Or, added "exclude" attribute to "Meta" inner class as shown below:
# "account/forms.py"
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class NewUserForm(UserCreationForm):
class Meta: # Here
model = User
exclude = ("first_name", "last_name") # Here
Then, I could solve the error.
- You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware
- Django Foreign Key: get related model?
- How to give initial value in modelform
-6π
Dropping to Django 1.7 seemed to do the trick. There didnβt seem to be an easy way to adapt the code to fit Django 1.8.