1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #412: Tenant group assignment is no longer mandatory

This commit is contained in:
Jeremy Stretch
2016-08-02 16:04:25 -04:00
parent 9f3647cd53
commit bc9158a74f
5 changed files with 54 additions and 7 deletions

View File

@@ -8,6 +8,18 @@ from utilities.forms import (
from .models import Tenant, TenantGroup
def bulkedit_tenantgroup_choices():
"""
Include an option to remove the currently assigned TenantGroup from a Tenant.
"""
choices = [
(None, '---------'),
(0, 'None'),
]
choices += [(g.pk, g.name) for g in TenantGroup.objects.all()]
return choices
def bulkedit_tenant_choices():
"""
Include an option to remove the currently assigned Tenant from an object.
@@ -46,7 +58,7 @@ class TenantForm(forms.ModelForm, BootstrapMixin):
class TenantFromCSVForm(forms.ModelForm):
group = forms.ModelChoiceField(TenantGroup.objects.all(), to_field_name='name',
group = forms.ModelChoiceField(TenantGroup.objects.all(), required=False, to_field_name='name',
error_messages={'invalid_choice': 'Group not found.'})
class Meta:
@@ -60,7 +72,7 @@ class TenantImportForm(BulkImportForm, BootstrapMixin):
class TenantBulkEditForm(forms.Form, BootstrapMixin):
pk = forms.ModelMultipleChoiceField(queryset=Tenant.objects.all(), widget=forms.MultipleHiddenInput)
group = forms.ModelChoiceField(queryset=TenantGroup.objects.all(), required=False)
group = forms.TypedChoiceField(choices=bulkedit_tenantgroup_choices, coerce=int, required=False, label='Group')
def tenant_group_choices():