django - Accessing foreign keys -



django - Accessing foreign keys -

i have next models:

class article(models.model): title = models.charfield(max_length=200, unique=false, null=false) rating = models.integerfield(default=0, null=false, unique=false) class shared(models.model): sender = models.foreignkey(user) article = models.foreignkey(article) class sharedmap(models.model): item = models.foreignkey(shared) receiver = models.foreignkey(user)

now execute next query:

def get_shared_feed(self): homecoming article.objects.filter(shared__sharedmap__receiver=self)

and list of articles expected. however:

{{ article.shared_set.count }}

gives me more 1 if articles shared before. want list of articles single sender(e.g. friend) each. instead, receive list of articles set of every user shared article.

the solution easy. had specify fields want homecoming using values:

blog_feed = article.objects.filter(shared__sharedmap__receiver=self).values('title', 'rating', 'shared__sender')

then on template:

{{ article.shared__sender }}

django django-models django-templates django-views

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -