mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Avoid overriding private attribute in super
This commit is contained in:
parent
2375d66f75
commit
5879671971
@ -571,16 +571,12 @@ class TagFilterField(forms.MultipleChoiceField):
|
||||
widget = StaticSelect2Multiple
|
||||
|
||||
def __init__(self, model, *args, **kwargs):
|
||||
# Only instanitate the field if the model supports tags (i.e. hide if not)
|
||||
if hasattr(model, 'tags'):
|
||||
self.model = model
|
||||
def get_choices():
|
||||
tags = model.tags.annotate(count=Count('extras_taggeditem_items')).order_by('name')
|
||||
return [(str(tag.slug), '{} ({})'.format(tag.name, tag.count)) for tag in tags]
|
||||
|
||||
# Choices are fetched during form initialization
|
||||
super().__init__(label='Tags', choices=self._choices, required=False, *args, **kwargs)
|
||||
|
||||
def _choices(self):
|
||||
tags = self.model.tags.annotate(count=Count('extras_taggeditem_items')).order_by('name')
|
||||
return [(str(tag.slug), '{} ({})'.format(tag.name, tag.count)) for tag in tags]
|
||||
# Choices are fetched each time the form is initialized
|
||||
super().__init__(label='Tags', choices=get_choices, required=False, *args, **kwargs)
|
||||
|
||||
|
||||
class FilterChoiceIterator(forms.models.ModelChoiceIterator):
|
||||
|
Loading…
Reference in New Issue
Block a user