I have 2 querysets and I am applying union on them but the strange thing is when I use only, it is selecting all fields from DB, and when I use values, it is selecting only given fields.
This is selecting all fields from the Physician table
doctors_models.Physician.objects.filter(
appointments__member=self.context['member']
).union(doctors_models.Physician.objects.filter(
appointments__booked_by=self.context['member']
)).only('id', 'name_prefix', 'first_name', 'middle_name', 'last_name', 'name_suffix')
BUT
This is selecting only specified fields from the Physician table
doctors_models.Physician.objects.filter(
appointments__member=self.context['member']
).union(doctors_models.Physician.objects.filter(
appointments__booked_by=self.context['member']
)).values('id', 'name_prefix', 'first_name', 'middle_name', 'last_name', 'name_suffix')
However, this is also selecting only specified fields but why should I define fields 2 times.
doctors_models.Physician.objects.filter(
appointments__member=self.context['member']
).only('id', 'name_prefix', 'first_name', 'middle_name', 'last_name', 'name_suffix').union(
doctors_models.Physician.objects.filter(
appointments__booked_by=self.context['member']
).only('id', 'name_prefix', 'first_name', 'middle_name', 'last_name', 'name_suffix'))