Skip to content

Instantly share code, notes, and snippets.

@infyloop
Created October 14, 2011 10:45
Show Gist options
  • Save infyloop/1286797 to your computer and use it in GitHub Desktop.
Save infyloop/1286797 to your computer and use it in GitHub Desktop.
Problem Statement:
a user belongs to one/many user_groups and one/many user_types
a channel belongs to one/many user_groups and one/many user_types
a video belongs to one/many channels
when a user logs in, he should be showed video from the channel which matches his user_group and user_type.
Solution done in django shell:
uobj = UserProfile.objects.get(user__username = "**")
ug = uobj.belongs_to_user_group
ut = uobj.belongs_to_user_type.all()
Video.objects.filter(belongs_to_channel__belongs_to_group__in=ug, belongs_to_channel__available_to_user_type__in = ut).distinct()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment