Here's the basics of setting up forms in django.
forms.py
from django import forms
from .models import SampleModel
class SampleForm(forms.ModelForm):
char_sample = forms.CharField(widget=forms.TextInput(attrs={'size': 300}))
class Meta:
model = SampleModel
fields = ('char_sample', 'text_sample')
By setting the form class, you can make more detailed settings for the form set in the model.
In the Meta
class, specify the target model and the fields to be displayed.
Here, we've covered setting up Django form classes. Next time I'll cover views.
Recommended Posts