User
id
name
Device
id
name
user-id
is_enabled
I want to select all Users who has
- At least one device enabled.
- Exactly 2 device enabled
- All devices enabled
Note: enabled means (Device.is_enabled = 1)
I know I can use annotate to get number of devices. But how to use annonate to get number of users who has exactly 2 enabled devices,
I am currently messing around with
User.objects.filter('device_set__is_enabled'=1)
Its giving List of Users who have at least one enabled device.
Dont know what to do next.
1 Answer