and i solved it in the view. dont know if this is the right way but it
works:

def topic_detail(request, slug):
    topic = get_object_or_404(Topic, slug=slug)
    t = topic.project_set.all()
    techlist = []
    for p in t:
        for t in  p.technologies.all():
            if t in techlist:
                pass
            else:
                techlist.append(t)
    return object_list(request,
                       queryset=topic.project_set.all(),
                       template_name='myapp/topic_detail.html',
                       extra_context={'object': topic, 'techlist':
techlist })



On Dec 10, 12:18 pm, andreas schmid <a.schmi...@gmail.com> wrote:
> ok im still stucking on this one:
>
> i dont think the regroup tag can help in this case....
> but i cant understand how i can query the technologies used within a
> specific topic.
>
> i mean i have alredy the projects assigned to this topic, now i need the
> technologies used by this projects.
>
> any ideas?
>
> Tim Valenta wrote:
> > It looks like the problem is that you're trying to group by
> > Technology, but your queryset is in Projects.  You could experiment
> > with the "regroup" template tag
> > (http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
> > )
>
> > It's a little hard to understand at first, but I think it's pretty
> > much what you're trying to do.  You would be able to remove the
> > ".distinct" part of your query because dictionary keys are already
> > can't be doubled.
>
> > Hope that helps.
>
> > Tim
>
> > On Nov 26, 7:04 am, andreas schmid <a.schmi...@gmail.com> wrote:
>
> >> hi,
>
> >> i have a question about retrieving related objects avoiding double entries.
> >> actually i have 3 models:
> >>     topics
> >>     projects
> >>     technologies
>
> >> the projects model has foreignkeys to topics and technologies. i have a
> >> view for the topic detail like this:
>
> >>     def topic_detail(request, slug):
> >>         topic = get_object_or_404(Topic, slug=slug)
> >>         return object_list(request,
> >>                            queryset=topic.project_set.all(),
> >>                            paginate_by=20,
> >>                            template_name='FSlabs/topic_detail.html',
> >>                            extra_context={ 'topic': topic })
>
> >> in the template i can loop trough the projects and  get those  assigned
> >> to this topic.
> >> but im having problems to retrieve the technologies used by those
> >> projects without having double entries.
>
> >> i tried this in the template with a list for every project
> >> assigned...which of course is not what i want:
>
> >>     {% for project in object_list  %}
> >>             {% for technology in project.technologies.distinct %}
> >>                 <a href="{{ technology.get_absolute_url }}">{{
> >>     technology.title }}</a>
> >>                 {% if forloop.last %}{% else %}
> >>                 {% ifequal forloop.revcounter0 1 %}and {% else %}, {%
> >>     endifequal %}
> >>                 {% endif %}
> >>             {% endfor %}
> >>         {% endfor %}
>
> >> can somebody point me to the right way to get what i need?
>
> >> thx
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to