9👍
✅
Thanks for your help guys, finally figured it out:
qs = StoreEvent.objects.filter(
store__in=Store.objects.filter(
available_staff__in=UserStore.objects.filter(user=user)
)
).order_by('date')
it results in 3 SQL SELECTs but does the trick…
47👍
Order by Date for all users:
queryset = StoreEvent.objects.all().order_by('-date')
To filter by user:
queryset = StoreEvent.objects.filter(stores__user=request.user).order_by('-date')
- [Django]-Problems extend change_form.html in django admin
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- [Django]-How to format time in django-rest-framework's serializer?
1👍
queryset = StoreEvent.objects.filter(store__in=UserStore.objects.filter(user__id=1).store).order_by('store__name', '-date')
or more graciously
user = User.objects.get(username="foo")
user_stores = user.stores.all()
store_events = StoreEvent.objects.filter(store__in=user_stores).order_by('store__name', '-date')
- [Django]-Django connection to postgres by docker-compose
- [Django]-Access web server on VirtualBox/Vagrant machine from host browser?
- [Django]-Django REST Framework (DRF): Set current user id as field value
Source:stackexchange.com