Fix asset sample data command

This commit is contained in:
2022-02-15 02:40:20 +00:00
parent 27bb3f1d8e
commit d9664422c5
3 changed files with 14 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ import random
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from django.db.utils import IntegrityError
from django.utils import timezone
from reversion import revisions as reversion
@@ -125,5 +126,9 @@ class Command(BaseCommand):
if i % 3 == 0:
asset.purchased_from = random.choice(self.suppliers)
asset.clean()
asset.save()
with transaction.atomic():
try:
asset.clean()
asset.save()
except IntegrityError:
pass