GrantU
GrantU

Reputation: 6555

Django form inherit - change fields

I want to change the order of a NewForm field to have name first. But I have a situation below where my NewForm inherits from OldForm and this gives errors.

ModelForm has no model class specified.

However, I don't see why I should add the model in again.

class OldForm(forms.ModelForm):
    address = Address()

    class Meta:
        model = Address
        fields = ('address')

class NewForm(OldForm):
    name = Name()


    class Meta:
        fields = ('name', 'address')

Upvotes: 1

Views: 1158

Answers (1)

professorDante
professorDante

Reputation: 2405

You can inherit your Meta class too:

class NewForm(OldForm):
    name = Name()


    class Meta(OldForm.Meta):
        fields = ('name', 'address')

Then your NewForm class has its model set as Address.

Upvotes: 4

Related Questions