mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Fixes #19444: Fix changeloggin for contact group assignments
This commit is contained in:
parent
8baf15771a
commit
abeed474f6
@ -0,0 +1,71 @@
|
|||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tenancy', '0019_contactgroup_comments_tenantgroup_comments'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.SeparateDatabaseAndState(
|
||||||
|
state_operations=[
|
||||||
|
# Remove the "through" models from the M2M field
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='contact',
|
||||||
|
name='groups',
|
||||||
|
field=models.ManyToManyField(
|
||||||
|
blank=True,
|
||||||
|
related_name='contacts',
|
||||||
|
related_query_name='contact',
|
||||||
|
to='tenancy.contactgroup'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
# Remove the ContactGroupMembership model
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='ContactGroupMembership',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
database_operations=[
|
||||||
|
# Rename ContactGroupMembership table
|
||||||
|
migrations.AlterModelTable(
|
||||||
|
name='ContactGroupMembership',
|
||||||
|
table='tenancy_contact_groups',
|
||||||
|
),
|
||||||
|
# Rename the 'group' column (also renames its FK constraint)
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='contactgroupmembership',
|
||||||
|
old_name='group',
|
||||||
|
new_name='contactgroup',
|
||||||
|
),
|
||||||
|
# Rename PK sequence
|
||||||
|
migrations.RunSQL(
|
||||||
|
'ALTER TABLE tenancy_contactgroupmembership_id_seq '
|
||||||
|
'RENAME TO tenancy_contact_groups_id_seq'
|
||||||
|
),
|
||||||
|
# Rename indexes
|
||||||
|
migrations.RunSQL(
|
||||||
|
'ALTER INDEX tenancy_contactgroupmembership_pkey '
|
||||||
|
'RENAME TO tenancy_contact_groups_pkey'
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
'ALTER INDEX tenancy_contactgroupmembership_contact_id_04a138a7 '
|
||||||
|
'RENAME TO tenancy_contact_groups_contact_id_84c9d84f'
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
'ALTER INDEX tenancy_contactgroupmembership_group_id_bc712dd0 '
|
||||||
|
'RENAME TO tenancy_contact_groups_contactgroup_id_5c8d6c5a'
|
||||||
|
),
|
||||||
|
migrations.RunSQL(
|
||||||
|
'ALTER INDEX unique_group_name '
|
||||||
|
'RENAME TO tenancy_contact_groups_contact_id_contactgroup_id_f4434f2c_uniq'
|
||||||
|
),
|
||||||
|
# Rename foreign key constraint for contact_id
|
||||||
|
migrations.RunSQL(
|
||||||
|
'ALTER TABLE tenancy_contact_groups '
|
||||||
|
'RENAME CONSTRAINT tenancy_contactgroup_contact_id_04a138a7_fk_tenancy_c '
|
||||||
|
'TO tenancy_contact_grou_contact_id_84c9d84f_fk_tenancy_c'
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@ -13,7 +13,6 @@ __all__ = (
|
|||||||
'ContactAssignment',
|
'ContactAssignment',
|
||||||
'Contact',
|
'Contact',
|
||||||
'ContactGroup',
|
'ContactGroup',
|
||||||
'ContactGroupMembership',
|
|
||||||
'ContactRole',
|
'ContactRole',
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,7 +50,6 @@ class Contact(PrimaryModel):
|
|||||||
groups = models.ManyToManyField(
|
groups = models.ManyToManyField(
|
||||||
to='tenancy.ContactGroup',
|
to='tenancy.ContactGroup',
|
||||||
related_name='contacts',
|
related_name='contacts',
|
||||||
through='tenancy.ContactGroupMembership',
|
|
||||||
related_query_name='contact',
|
related_query_name='contact',
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
@ -97,18 +95,6 @@ class Contact(PrimaryModel):
|
|||||||
return self.name
|
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):
|
class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedModel):
|
||||||
object_type = models.ForeignKey(
|
object_type = models.ForeignKey(
|
||||||
to='contenttypes.ContentType',
|
to='contenttypes.ContentType',
|
||||||
|
Loading…
Reference in New Issue
Block a user