mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 17:26:10 -06:00
#9047 - Fix constraint check
This commit is contained in:
parent
5fa3146912
commit
1b6e67ba0a
@ -27,7 +27,7 @@ def create_provideraccounts_from_providers(apps, schema_editor):
|
|||||||
#
|
#
|
||||||
def revert_provideraccounts_from_providers(apps, schema_editor):
|
def revert_provideraccounts_from_providers(apps, schema_editor):
|
||||||
ProviderAccount = apps.get_model('circuits', 'ProviderAccount')
|
ProviderAccount = apps.get_model('circuits', 'ProviderAccount')
|
||||||
provideraccounts = ProviderAccount.objects.all().orderby('pk')
|
provideraccounts = ProviderAccount.objects.all().order_by('pk')
|
||||||
for provideraccount in provideraccounts:
|
for provideraccount in provideraccounts:
|
||||||
if provideraccounts.filter(provider=provideraccount.provider)[0] == provideraccount:
|
if provideraccounts.filter(provider=provideraccount.provider)[0] == provideraccount:
|
||||||
provideraccount.provider.account = provideraccount.account
|
provideraccount.provider.account = provideraccount.account
|
||||||
@ -66,7 +66,7 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
migrations.AddConstraint(
|
migrations.AddConstraint(
|
||||||
model_name='provideraccount',
|
model_name='provideraccount',
|
||||||
constraint=models.UniqueConstraint(fields=('provider', 'account'), name='circuits_provideraccount_unique_provider_account'),
|
constraint=models.UniqueConstraint(condition=models.Q(('account', ''), _negated=True), fields=('provider', 'account'), name='circuits_provideraccount_unique_provider_account'),
|
||||||
),
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
create_provideraccounts_from_providers, revert_provideraccounts_from_providers
|
create_provideraccounts_from_providers, revert_provideraccounts_from_providers
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Q
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from netbox.models import PrimaryModel
|
from netbox.models import PrimaryModel
|
||||||
@ -81,7 +82,8 @@ class ProviderAccount(PrimaryModel):
|
|||||||
),
|
),
|
||||||
models.UniqueConstraint(
|
models.UniqueConstraint(
|
||||||
fields=('provider', 'account'),
|
fields=('provider', 'account'),
|
||||||
name='%(app_label)s_%(class)s_unique_provider_account'
|
name='%(app_label)s_%(class)s_unique_provider_account',
|
||||||
|
condition=~Q(account="")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user