Filtering a custom field added to the User Model in Django -


class snippet(models.model):     language = models.charfield(max_length=25)     content = models.textfield(max_length=500)     description = models.charfield(max_length=200)     privacy_choices = (         ('me', 'me'),         ('friends', 'friends'),         ('everyone', 'everyone'),     )     privacy = models.charfield(max_length=8,choices=privacy_choices,default='everyone')  class siteuser(models.model):     user = models.onetoonefield(user)     snippets = models.manytomanyfield('snippet', null=true, blank=true)     friends = models.manytomanyfield(user, related_name='friends') 

i trying check if current user friend of person page viewing. then, based off of whether friend, need show snippets right privacy level.

so if friend snippets privacy = 'everyone' or 'friends', if stranger, ones privacy = 'everyone', etc.

i'm able figure out required privacy level easily, i'm having hard time correct filtering on snippets.

here how check if friend:

user.siteuser.friends.get(username=request.user.username) 

and here how i'm trying filter snippets privacy level:

saved_snippets = user.siteuser.snippets.filter(privacy='everyone') 

for reason filtering isn't working @ all, don't understand because do:

saved_snippets = user.siteuser.snippets.all() 

and correctly gets snippets user, i'm not sure why all() works, not filter()


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -