I have three databases - table models (Django Models ).

In which there is a different amount of data - a different number of rows of elements in the database table. One table has 100 rows - the other model table has 150 rows.

I’m going to migrate the data from these models to another one - a general summary table model. Sequentially transferring data from each model. How can I do this - to transfer data to the summary table - only by the size (number of rows) of the smallest model table?

def file_upload_button(request):
context = {}
queryset_summ = Model_upload_summ.objects.all()
queryset_1 = Model_upload_teplo.objects.all()
queryset_2 = Model_upload_gvs.objects.all()
queryset_3 = Model_upload_topgas.objects.all()
datetime_1 = [d.datetime for d in queryset_1]
datetime_2 = [d.datetime for d in queryset_2]
datetime_3 = [d.datetime for d in queryset_3]
numbers_1 = len(datetime_1)
numbers_2 = len(datetime_2)
numbers_3 = len(datetime_3)
if numbers_1 <= numbers_2 and numbers_1 <= numbers_3:
# save numbers_1 (rows of queryset Models) into queryset_summ or Model_upload_summ
elif numbers_2 <= numbers_1 and numbers_2 <= numbers_3:
# not active if first condition (above) id done
elif numbers_3 <= numbers_1 and numbers_3 <= numbers_2:
# not active if first condition (above) id done

def file_upload_button(request):
context = {}
queryset_summ = Model_upload_summ.objects.all()
queryset_1 = Model_upload_teplo.objects.all()
queryset_2 = Model_upload_gvs.objects.all()
queryset_3 = Model_upload_topgas.objects.all()
datetime_1 = [d.datetime for d in queryset_1]
datetime_2 = [d.datetime for d in queryset_2]
datetime_3 = [d.datetime for d in queryset_3]
numbers_1 = len(datetime_1)
numbers_2 = len(datetime_2)
numbers_3 = len(datetime_3)
list_numbers = [numbers_1, numbers_2, numbers_3]
min_value_numbers = min(list_numbers)
# save min_value_numbers (rows of queryset Models) into queryset_summ or Model_upload_summ
# how to save only (min_value_numbers) - from first to min_value_numbers - from export all models into queryset_summ or Model_upload_summ
if numbers_1 <= numbers_2 and numbers_1 <= numbers_3:
# save numbers_1 (rows of queryset Models) into queryset_summ or Model_upload_summ
elif numbers_2 <= numbers_1 and numbers_2 <= numbers_3:
# not active if first condition (above) id done
elif numbers_3 <= numbers_1 and numbers_3 <= numbers_2:
# not active if first condition (above) id done