mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -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>
|
<td>
|
||||||
{{ field.help_text|default:field.label }}
|
{{ field.help_text|default:field.label }}
|
||||||
{% if field.choices %}
|
{% 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' %}
|
{% elif field|widget_type == 'dateinput' %}
|
||||||
<br /><small class="text-muted">Format: YYYY-MM-DD</small>
|
<br /><small class="text-muted">Format: YYYY-MM-DD</small>
|
||||||
{% elif field|widget_type == 'checkboxinput' %}
|
{% elif field|widget_type == 'checkboxinput' %}
|
||||||
|
@ -63,19 +63,23 @@ def bettertitle(value):
|
|||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@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).
|
Returns a number (default: 3) of example choices for a ChoiceFiled (useful for CSV import forms).
|
||||||
"""
|
"""
|
||||||
choices = []
|
examples = []
|
||||||
for id, label in value:
|
if hasattr(field, 'queryset'):
|
||||||
if len(choices) == arg:
|
choices = [(obj.pk, getattr(obj, field.to_field_name)) for obj in field.queryset[:arg+1]]
|
||||||
choices.append('etc.')
|
else:
|
||||||
|
choices = field.choices
|
||||||
|
for id, label in choices:
|
||||||
|
if len(examples) == arg:
|
||||||
|
examples.append('etc.')
|
||||||
break
|
break
|
||||||
if not id:
|
if not id:
|
||||||
continue
|
continue
|
||||||
choices.append(label)
|
examples.append(label)
|
||||||
return ', '.join(choices) or 'None'
|
return ', '.join(examples) or 'None'
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user