27π
When you are creating a form using model, you need to specify which fields you want to be included in the form.
For example you have a model with the named Article and you want to create a form for the model article.
pub_date, headline, content, reporter these are the fields in the model.
If you choose to include all the fields you do like this.
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = '__all__'
If you want to specify which fields you want to include
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ['pub_date', 'headline', 'content']
If you want to exclude a certain fields and use the remaining then use as follows
class ArticleForm(ModelForm):
class Meta:
model = Article
exclude = ['headline']
Coming to your error, it says you can use ModelForm with out using one of the two options that is using fields or exclude.
6π
class TopicForm(forms.ModelForm):
class Meta:
model = Topic
fields = '__all__' # or whatever fields you want ('field_a', )
- Create Read-Only MySQL Database Connection in Django
- How to access user names and profiles with django-allauth
- Using Django's collectstatic with boto S3 throws "Error 32: Broken Pipe" after a while
3π
I had the exact same error and turns out I had written βfieldβ instead of βfields
β
- Django Pipeline, Heroku, and SASS
- How to append extra data to the existing serializer in django
- Non-queryset data ordering in django-tables2
- After login the `rest-auth`, how to return more information?
2π
class BlogForm(forms.ModelForm):
class Meta:
model=Blog
fields='__all__'
check name fields
, you type incorrectly, or capital F is used.
0π
from django import forms
from .models import Dforms
class Forms(forms.ModelForm):
class Meta:
model = Dforms
fields = "__all__"
0π
I had the same problem, my mistake was to miss the name of a class in my appβs forms.py file
- How to connect PyCharm to a Heroku postgres database
- Django β multiple pluralization in admin model
- Can't fix "zipimport.ZipImportError: can't decompress data; zlib not available" when I type in "python3.6 get-pip.py"
- Django REST Framework β multiple models / APIs?
- Global set up in django test framework?
-1π
i had aslo same problem after i checked my code again then i find i had written field
istead of fields
so first check name fields, you may have type incorrectly.
- Using urls names in views
- Pip and virtualenv installing parts of django in the wrong place
- Add checkbox and delete actions to customized Django admin change_list