mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -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
|
widget = StaticSelect2Multiple
|
||||||
|
|
||||||
def __init__(self, model, *args, **kwargs):
|
def __init__(self, model, *args, **kwargs):
|
||||||
# Only instanitate the field if the model supports tags (i.e. hide if not)
|
def get_choices():
|
||||||
if hasattr(model, 'tags'):
|
tags = model.tags.annotate(count=Count('extras_taggeditem_items')).order_by('name')
|
||||||
self.model = model
|
return [(str(tag.slug), '{} ({})'.format(tag.name, tag.count)) for tag in tags]
|
||||||
|
|
||||||
# Choices are fetched during form initialization
|
# Choices are fetched each time the form is initialized
|
||||||
super().__init__(label='Tags', choices=self._choices, required=False, *args, **kwargs)
|
super().__init__(label='Tags', choices=get_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]
|
|
||||||
|
|
||||||
|
|
||||||
class FilterChoiceIterator(forms.models.ModelChoiceIterator):
|
class FilterChoiceIterator(forms.models.ModelChoiceIterator):
|
||||||
|
Loading…
Reference in New Issue
Block a user