mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
InstanceLink unique constraint source and target
Prevent creating InstanceLinks with duplicate source and target pairings. Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
@@ -141,4 +141,10 @@ class Migration(migrations.Migration):
|
|||||||
help_text='The target receptor address of this peer link.', on_delete=django.db.models.deletion.CASCADE, to='main.receptoraddress'
|
help_text='The target receptor address of this peer link.', on_delete=django.db.models.deletion.CASCADE, to='main.receptoraddress'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name='instancelink',
|
||||||
|
constraint=models.UniqueConstraint(
|
||||||
|
fields=('source', 'target'), name='unique_source_target', violation_error_message='Field source and target must be unique together.'
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ class HasPolicyEditsMixin(HasEditsMixin):
|
|||||||
class InstanceLink(BaseModel):
|
class InstanceLink(BaseModel):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("id",)
|
ordering = ("id",)
|
||||||
|
# add constraint for source and target to be unique together
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(
|
||||||
|
fields=["source", "target"],
|
||||||
|
name="unique_source_target",
|
||||||
|
violation_error_message=_("Field source and target must be unique together."),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
source = models.ForeignKey('Instance', on_delete=models.CASCADE, help_text=_("The source instance of this peer link."))
|
source = models.ForeignKey('Instance', on_delete=models.CASCADE, help_text=_("The source instance of this peer link."))
|
||||||
target = models.ForeignKey('ReceptorAddress', on_delete=models.CASCADE, help_text=_("The target receptor address of this peer link."))
|
target = models.ForeignKey('ReceptorAddress', on_delete=models.CASCADE, help_text=_("The target receptor address of this peer link."))
|
||||||
|
|||||||
Reference in New Issue
Block a user