Skip to content

Commit

Permalink
edit migration
Browse files Browse the repository at this point in the history
  • Loading branch information
LocalNewsTV committed Nov 20, 2023
1 parent d7d90b5 commit 4b0c219
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ def populate_wells_with_attachment_table(apps, schema_editor):
# Get all well tag numbers that don't have an entry in WellAttachment
well_tag_numbers_without_attachment = Well.objects.exclude(wellattachment__isnull=False).values_list('well_tag_number', flat=True)

well_attachments_to_create = [WellAttachment(well_tag_number=tag_number) for tag_number in well_tag_numbers_without_attachment]
well_attachments_to_create = []

# Iterate through each tag number and create WellAttachment instances
for tag_number in well_tag_numbers_without_attachment:
well_instance = Well.objects.get(well_tag_number=tag_number)
well_attachment_instance = WellAttachment(well_tag_number=well_instance)
well_attachments_to_create.append(well_attachment_instance)

WellAttachment.objects.bulk_create(well_attachments_to_create)


class Migration(migrations.Migration):

Expand Down

0 comments on commit 4b0c219

Please sign in to comment.