Re: Filter queryset based on another model's foreign key in a class based view.

2017-06-10 Thread Ajat Prabha
Thanks, Melvyn Sopacua, Now it all makes sense. On Saturday, 10 June 2017 21:54:57 UTC+5:30, Melvyn Sopacua wrote: > > On Saturday 10 June 2017 08:22:20 Ajat Prabha wrote: > > > > > > > class TopicDetailView(generic.DetailView): > > > > model = Topic > > > > context_object_name = 'topic' > > >

Re: Filter queryset based on another model's foreign key in a class based view.

2017-06-10 Thread Melvyn Sopacua
On Saturday 10 June 2017 08:22:20 Ajat Prabha wrote: > class TopicDetailView(generic.DetailView): > > model = Topic > > context_object_name = 'topic' > > template_name = 'topicdetail.html' > > def get_context_data(self, **kwargs): > > context = super(TopicDetailView, > >

Re: Filter queryset based on another model's foreign key in a class based view.

2017-06-10 Thread Alceu Rodrigues de Freitas Junior
See "reverse lookup" or "_set" function in order to do that. Your Answer model has a FK for the Topic, but not the other way around. See https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Generic_views, "Creating the Detail View template" for details about it, there are some li

Filter queryset based on another model's foreign key in a class based view.

2017-06-10 Thread Ajat Prabha
Hi there, I'm having trouble in filtering objects of a model based on another model's foreign key. The scenario is, I've got a forum homepage and when a topic is clicked, it opens its DetailView. Now if I try to get all answers in the database there's no issue, but I want to get only the answers