Skip to content

Update forms.py to fix #284 #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pylint_django/checkers/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Models."""
from astroid.nodes import Assign, ClassDef
from astroid.nodes import Assign, AssignName, ClassDef

from pylint.interfaces import IAstroidChecker
from pylint.checkers.utils import check_messages
Expand Down Expand Up @@ -41,7 +41,8 @@ def visit_classdef(self, node):
return

for child in meta.get_children():
if not isinstance(child, Assign):
if (not isinstance(child, Assign)
or not isinstance(child.targets[0], AssignName)):
continue

if child.targets[0].name == 'exclude':
Expand Down
9 changes: 9 additions & 0 deletions pylint_django/tests/input/func_noerror_forms_py33.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ class Meta:
class TestModelFormSubclass(forms.ModelForm):
class Meta:
pass


class TestFormWidgetAssignment(forms.Form):

multi_field = forms.MultipleChoiceField(choices=[('1', 'First'), ('2', 'Second')])

class Meta:
widgets = {}
widgets['multi_field'] = forms.CheckboxSelectMultiple