mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-22 08:48:41 +02:00
17170 Add ability to add contacts to multiple contact groups (#18885)
* 17170 Allow multiple Group assignments for Contacts * 17170 update docs * 17170 update api, detail view, graphql * 17170 fixes * 17170 fixes * 17170 fixes * 17170 fixes * 17170 fixes * 17170 fixes * 17170 fix bulk import * 17170 test fixes * 17170 test fixes * 17170 test fixes * 17178 review changes * 17178 review changes * 17178 review changes * 17178 review changes * 17178 review changes * 17178 review changes * 17170 update migration * 17170 bulk edit form
This commit is contained in:
@@ -13,6 +13,7 @@ __all__ = (
|
||||
'ContactAssignment',
|
||||
'Contact',
|
||||
'ContactGroup',
|
||||
'ContactGroupMembership',
|
||||
'ContactRole',
|
||||
)
|
||||
|
||||
@@ -47,12 +48,12 @@ class Contact(PrimaryModel):
|
||||
"""
|
||||
Contact information for a particular object(s) in NetBox.
|
||||
"""
|
||||
group = models.ForeignKey(
|
||||
groups = models.ManyToManyField(
|
||||
to='tenancy.ContactGroup',
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='contacts',
|
||||
blank=True,
|
||||
null=True
|
||||
through='tenancy.ContactGroupMembership',
|
||||
related_query_name='contact',
|
||||
blank=True
|
||||
)
|
||||
name = models.CharField(
|
||||
verbose_name=_('name'),
|
||||
@@ -84,17 +85,11 @@ class Contact(PrimaryModel):
|
||||
)
|
||||
|
||||
clone_fields = (
|
||||
'group', 'name', 'title', 'phone', 'email', 'address', 'link',
|
||||
'groups', 'name', 'title', 'phone', 'email', 'address', 'link',
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('group', 'name'),
|
||||
name='%(app_label)s_%(class)s_unique_group_name'
|
||||
),
|
||||
)
|
||||
verbose_name = _('contact')
|
||||
verbose_name_plural = _('contacts')
|
||||
|
||||
@@ -102,6 +97,18 @@ class Contact(PrimaryModel):
|
||||
return self.name
|
||||
|
||||
|
||||
class ContactGroupMembership(models.Model):
|
||||
group = models.ForeignKey(ContactGroup, related_name="+", on_delete=models.CASCADE)
|
||||
contact = models.ForeignKey(Contact, related_name="+", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['group', 'contact'], name='unique_group_name')
|
||||
]
|
||||
verbose_name = _('contact group membership')
|
||||
verbose_name_plural = _('contact group memberships')
|
||||
|
||||
|
||||
class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedModel):
|
||||
object_type = models.ForeignKey(
|
||||
to='contenttypes.ContentType',
|
||||
|
||||
Reference in New Issue
Block a user