-1

In my code, I currently have 2 models (Company and Individual Model)

Now I need to print both sets of data on the same report but it needs to be in alphabetical order

This is how I have referenced them in views.py separately

modelCompany = CompanyClass.objects.all().order_by('CompanyName')
modelIndividual = IndividualClass.objects.all().order_by('Surname')

But how would I be able to join them in the same list and organize them alphabetically?

Kyle
  • 169
  • 1
  • 8
  • Does this answer your question? [How can I combine two or more querysets in a Django view?](https://stackoverflow.com/questions/431628/how-can-i-combine-two-or-more-querysets-in-a-django-view) – rahul.m Feb 15 '22 at 09:41

1 Answers1

0

You can specify an empty dictionary and after querying for results of CompanyClass and IndividualClass, add them to your dictionary like this:

context = { Company: modelCompany, Individual: modelIndividual }

Then return this json object by JsonResponse or something like that

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459