mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Fixes #1358: Correct VRF example values in IP/prefix import forms
This commit is contained in:
parent
0655834938
commit
106627da04
@ -44,7 +44,7 @@
|
||||
<td>
|
||||
{{ field.help_text|default:field.label }}
|
||||
{% if field.choices %}
|
||||
<br /><small class="text-muted">Choices: {{ field.choices|example_choices }}</small>
|
||||
<br /><small class="text-muted">Choices: {{ field|example_choices }}</small>
|
||||
{% elif field|widget_type == 'dateinput' %}
|
||||
<br /><small class="text-muted">Format: YYYY-MM-DD</small>
|
||||
{% elif field|widget_type == 'checkboxinput' %}
|
||||
|
@ -63,19 +63,23 @@ def bettertitle(value):
|
||||
|
||||
|
||||
@register.filter()
|
||||
def example_choices(value, arg=3):
|
||||
def example_choices(field, arg=3):
|
||||
"""
|
||||
Returns a number (default: 3) of example choices for a ChoiceFiled (useful for CSV import forms).
|
||||
"""
|
||||
choices = []
|
||||
for id, label in value:
|
||||
if len(choices) == arg:
|
||||
choices.append('etc.')
|
||||
examples = []
|
||||
if hasattr(field, 'queryset'):
|
||||
choices = [(obj.pk, getattr(obj, field.to_field_name)) for obj in field.queryset[:arg+1]]
|
||||
else:
|
||||
choices = field.choices
|
||||
for id, label in choices:
|
||||
if len(examples) == arg:
|
||||
examples.append('etc.')
|
||||
break
|
||||
if not id:
|
||||
continue
|
||||
choices.append(label)
|
||||
return ', '.join(choices) or 'None'
|
||||
examples.append(label)
|
||||
return ', '.join(examples) or 'None'
|
||||
|
||||
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user