0

I am beginner to Django. I am trying to concatenate two QuerySets from the same Model. I don't need them to be in any specific order.

 normal_events = Events.objects.filter(date__day=day,is_weekly=False)
 weekly_events = Events.objects.filter(date__day=day%7,is_weekly=True)

I've tired this solution:

 events=normal_events + weekly_events

but obviously it doesn't work.

I saw this solution: https://stackoverflow.com/a/434755/3279262 and it works fine, but it is meant for different QuerySets.

Is there some simple way for same QuerySets?

Community
  • 1
  • 1
Ratelas
  • 1
  • 1
  • possible duplicate of [How to combine 2 or more querysets in a Django view?](http://stackoverflow.com/questions/431628/how-to-combine-2-or-more-querysets-in-a-django-view) – Brandon Taylor Jun 06 '15 at 16:29

2 Answers2

1

Instead of concatenating you can use Q objects and combine them with |

events = Events.objects.filter(Q(date__day=day,is_weekly=False) | Q(date__day=day%7,is_weekly=True))
koala
  • 119
  • 8
0

If you simply want to concatenate in any order, then you could try something like this:

events = normal_events | weekly_events

Which is very similar to what you wanted to try initially.