2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-04 20:51:00 +00:00

Fix constraint for address model (#5076)

* Fix constraint for address model

- Do not handle at database level
- Add a "validate_unique" method to the address model
- Fixes https://github.com/inventree/InvenTree/issues/5070

* Remove unique constraint rule

* Unit test fix

- Adjust unit test around new code

* Further unit test updates
This commit is contained in:
Oliver
2023-06-20 16:57:20 +10:00
committed by GitHub
parent b700b44c53
commit 303305e05f
3 changed files with 22 additions and 11 deletions

View File

@ -30,8 +30,4 @@ class Migration(migrations.Migration):
('company', models.ForeignKey(help_text='Select company', on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='company.company', verbose_name='Company')),
],
),
migrations.AddConstraint(
model_name='address',
constraint=models.UniqueConstraint(condition=models.Q(('primary', True)), fields=('company',), name='one_primary_per_company'),
),
]