mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-22 08:48:41 +02:00
Closes #3810: Preserve slug value when editing existing objects
This commit is contained in:
@@ -132,6 +132,13 @@ class SmallTextarea(forms.Textarea):
|
||||
pass
|
||||
|
||||
|
||||
class SlugWidget(forms.TextInput):
|
||||
"""
|
||||
Subclass TextInput and add a slug regeneration button next to the form field.
|
||||
"""
|
||||
template_name = 'widgets/sluginput.html'
|
||||
|
||||
|
||||
class ColorSelect(forms.Select):
|
||||
"""
|
||||
Extends the built-in Select widget to colorize each <option>.
|
||||
@@ -534,7 +541,8 @@ class SlugField(forms.SlugField):
|
||||
def __init__(self, slug_source='name', *args, **kwargs):
|
||||
label = kwargs.pop('label', "Slug")
|
||||
help_text = kwargs.pop('help_text', "URL-friendly unique shorthand")
|
||||
super().__init__(label=label, help_text=help_text, *args, **kwargs)
|
||||
widget = kwargs.pop('widget', SlugWidget)
|
||||
super().__init__(label=label, help_text=help_text, widget=widget, *args, **kwargs)
|
||||
self.widget.attrs['slug-source'] = slug_source
|
||||
|
||||
|
||||
|
||||
8
netbox/utilities/templates/widgets/sluginput.html
Normal file
8
netbox/utilities/templates/widgets/sluginput.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<div class="input-group">
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default reslugify" type="button" title="Regenerate slug">
|
||||
<i class="fa fa-refresh"></i>
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
Reference in New Issue
Block a user