I have a Django 1.5 form that looks like this (simplified):
class BidForm(forms.ModelForm):
class Meta:
fields = (
)
model = Bid
def __init__(self, *args, **kwargs):
super(BidForm, self).__init__(*args, **kwargs)
something()
When I run Pylint on this, I get a this error:
E1002:<line,row>:BidForm.__init__: Use of super on an old style class
I assume this means the Django's forms.ModelForm is an old-style class and per the python docs my call to super is not happening and is therefore extraneous. Is this true? Can I just delete the super call without effect?
The similarities are that they both generate sets of form inputs using widgets, and both validate data sent by the browser. The differences are that ModelForm gets its field definition from a specified model class, and also has methods that deal with saving of the underlying model to the database. Save this answer.
Django Model Form It is a class which is used to create an HTML form by using the Model. It is an efficient way to create a form without writing HTML code. Django automatically does it for us to reduce the application development time.
Django provides a Form class which is used to create HTML forms. It describes a form and how it works and appears. It is similar to the ModelForm class that creates a form by using the Model, but it does not require the Model.
No. Pylint, great though it is, is far from infallible, and in this case has just got it wrong. ModelForm is a new style class and the super is needed.
This error/warning has nothing to do with the ModelForm class and has to do with:
class Meta:
fields = ()
model = Bid
You just need to suppress the warning:
class Meta: # pylint: disable=C1001
fields = ()
model = Bid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With