|
|
@@ -1,9 +1,11 @@
|
|
|
+from django.contrib.contenttypes.models import ContentType
|
|
|
from django.utils.translation import gettext as _
|
|
|
from netbox.forms import NetBoxModelImportForm
|
|
|
from tenancy.models import *
|
|
|
-from utilities.forms.fields import CSVModelChoiceField, SlugField
|
|
|
+from utilities.forms.fields import CSVContentTypeField, CSVModelChoiceField, SlugField
|
|
|
|
|
|
__all__ = (
|
|
|
+ 'ContactAssignmentImportForm',
|
|
|
'ContactImportForm',
|
|
|
'ContactGroupImportForm',
|
|
|
'ContactRoleImportForm',
|
|
|
@@ -81,3 +83,27 @@ class ContactImportForm(NetBoxModelImportForm):
|
|
|
class Meta:
|
|
|
model = Contact
|
|
|
fields = ('name', 'title', 'phone', 'email', 'address', 'link', 'group', 'description', 'comments', 'tags')
|
|
|
+
|
|
|
+
|
|
|
+class ContactAssignmentImportForm(NetBoxModelImportForm):
|
|
|
+ content_type = CSVContentTypeField(
|
|
|
+ queryset=ContentType.objects.all(),
|
|
|
+ help_text=_("One or more assigned object types")
|
|
|
+ )
|
|
|
+ contact = CSVModelChoiceField(
|
|
|
+ queryset=Contact.objects.all(),
|
|
|
+ to_field_name='name',
|
|
|
+ help_text=_('Assigned contact')
|
|
|
+ )
|
|
|
+ role = CSVModelChoiceField(
|
|
|
+ queryset=ContactRole.objects.all(),
|
|
|
+ to_field_name='name',
|
|
|
+ help_text=_('Assigned role')
|
|
|
+ )
|
|
|
+
|
|
|
+ # Remove the tags field added by NetBoxModelImportForm (unsupported by ContactAssignment)
|
|
|
+ tags = None
|
|
|
+
|
|
|
+ class Meta:
|
|
|
+ model = ContactAssignment
|
|
|
+ fields = ('content_type', 'object_id', 'contact', 'priority', 'role')
|