add_establishment_description command
This commit is contained in:
parent
6fe8252025
commit
7be3c2b93f
|
|
@ -0,0 +1,31 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
|
||||
from establishment.models import Establishment
|
||||
from transfer.models import Descriptions
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Add description values from old db to new db'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
count = 0
|
||||
|
||||
queryset = Descriptions.objects.all()
|
||||
for obj in queryset:
|
||||
try:
|
||||
establishment = Establishment.objects.get(old_id=obj.establishment.id)
|
||||
except Establishment.DoesNotExist:
|
||||
continue
|
||||
except Establishment.MultipleObjectsReturned:
|
||||
establishment = Establishment.objects.filter(old_id=obj.establishment.id).first()
|
||||
else:
|
||||
description = establishment.description
|
||||
description.update({
|
||||
obj.locale: obj.text
|
||||
})
|
||||
establishment.description = description
|
||||
establishment.save()
|
||||
count += 1
|
||||
break
|
||||
|
||||
self.stdout.write(self.style.WARNING(f'Updated {count} objects.'))
|
||||
Loading…
Reference in New Issue
Block a user