1
votes

I have a base model class called CommonInfo with props like name, email, password etc.

Then have a User model (subclass of CommonInfo) with things like profile image, username, and integer field called reputation.

Now I want to display a form for registration without the reputation field, so my view function looks like this :

def reg(request):
    form = modelform_factory(User, exclude=('reputation'))
    return render(request, 'reg.html', {
        'form': form,
    });

But the thing is that fields in a form are ordered just like in models (name, email, password, profile_image, username).

I want to reorder those fields (put username on the first place, then name and email) but I don't want to create class for this form, simply because the model and the form are very to similar (only difference is the reputation field)

How can I achieve this ?

1

1 Answers

1
votes

Quickest way to do this is :

class RegForm(forms.ModelForm):
    class Meta:
       model=User
       fields=['username', 'name', 'email' ...]