python - How to filter from two conditions? -


i have model user groups:

class profilegroup(models.model):     user = models.manytomanyfield(user)     name = models.charfield(max_length=100) 

and model article:

class article(models.model):     title = models.charfield(max_length=200)     text = models.textfield()     group = models.foreignkey(profilegroup)     owner = models.foreignkey(user) 

the user can edit own articles , articles groups assigned.

how retrieve user articles , groups? need use q? maybe suffice filter?

articles = article.object.filter(.... 

to user's articles:

article.objects.filter(owner=user) 

to articles belong 1 of user's groups.

article.objects.filter(group__user=user) 

you can use q articles belong user or 1 of user's groups.

article.objects.filter(q(owner=user)|q(group__user=user)) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -