[Answered ]-Generating custom forms from DB schema

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

👤satoru

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 ModelForms 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.

Leave a comment