Skip to content

Commit

Permalink
Merge pull request #1096 from xzzy/master2
Browse files Browse the repository at this point in the history
Create update_identification_document_fields.py
  • Loading branch information
xzzy authored Aug 12, 2024
2 parents f6aa3aa + 992be2c commit 837b1da
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.core.management.base import BaseCommand
from django.db.models import Q

import logging
import pathlib

from ledger.accounts.models import PrivateDocument

logger = logging.getLogger(__name__)


class Command(BaseCommand):
help = 'Updates all Identification document records to have all required fields populated.'

def handle(self, *args, **options):
try:
logger.info('Running command {}'.format(__name__))

private_docs = PrivateDocument.objects.filter(Q(name=None)|Q(name="")|Q(extension=None)|Q(file_group=None))

for i in private_docs:
i.name = pathlib.Path(i.upload.name).name
i.extension = pathlib.Path(i.upload.name
).suffix if (len(
pathlib.Path(
i.upload.name
).suffix) <= PrivateDocument._meta.get_field('extension').max_length
) else ""
i.file_group = 1
i.save(update_fields=["name","extension","file_group"])

logger.info('Command {} finished'.format(__name__))

except Exception as e:
logger.error('Error command {0} : {1}'.format(
__name__, e))

0 comments on commit 837b1da

Please sign in to comment.