I have created a model with some classes:
class Student(models.Model):
name = models.CharField(max_length=40)
last_name = models.CharFIeld(max_length=40)
(...)
and in the same models.py file at the bottom I’ve added a class corresponding to one of my models so i can create a form:
class StudentForm(ModelForm):
class Meta:
model = Student
How do I customize form fields created via ModelForm class ? I was reading django Documentation and I can’t understand overriding the default types part.
For example, in documentation they say this will work:
class ArticleForm(ModelForm):
pub_date = DateField(label='Publication date')
class Meta:
model = Article
but when i type my values it’s not working. I can’t define my label:
class StudentForm(ModelForm):
name = CharField(label='New label')
class Meta:
model = Student
Do i have to create a file like forms.py with identical fields as in Model class and then customize them ? Is it possible to change single field css attributes like width, height using only Model Forms ?
Field for form use a difference library to create a from. You need to import
django.formsand useform.XXXfor specific Field