1👍
Use ModelForm
and override any field you wanna customize by explicitly declaring them.
If you want to set field attributes like class
and id
, you need to do something like this:
name = forms.CharField(
widget=forms.TextInput(attrs={'class':'special'}))
In case you are interested, you may change the order of the fields by specifying a fields
sequence in your Meta
class:
class Meta:
model = YourModel
fields = ('title', 'content')
You may read the full documentation here:
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs
1👍
If you haven’t already, take a look at Django’s ModelForm. I am assuming that you have models mapped to the tables in question. Vanilla ModelForm
instances will work without JS. However ModelForm
s are usually defined ahead of time and not constructed on the fly. I suppose they can be created on the fly but that would be a bit tricky.
- [Answered ]-Where are template tags include files expected to be found in Django framework
- [Answered ]-Django form fails to render_to_response
- [Answered ]-Django – multiple queries into one
- [Answered ]-Sending emails with messages dependent on if statements Django