mirror of
https://github.com/ansible/awx.git
synced 2026-01-10 15:32:07 -03: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:
parent
eeae1d59d4
commit
21fd6af0f9
@ -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'
|
||||
),
|
||||
),
|
||||
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 Meta:
|
||||
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."))
|
||||
target = models.ForeignKey('ReceptorAddress', on_delete=models.CASCADE, help_text=_("The target receptor address of this peer link."))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user