On Mon, 2008-02-11 at 23:42 +0100, Nicolas Steinmetz wrote:
> Hello,
>
> In my app, I have the following :
> - "Userskill" allows a given user to link 1 to n skills thanks to a
> Foreign Key to "Skill" model
> - In Skill model there is a foreign key to "Skilldomain".
>
> I would like to display all the skills for a given user by skill domains.
>
> I have such models (simplified) :
>
> class Skilldomain(models.Model):
> name = models.CharField(_('Skill domain'), max_length=50)
>
> class Skill(models.Model):
> name = models.CharField(_('Skill'), max_length=50)
> domain = models.ForeignKey(Skilldomain, verbose_name=_('Skill domain'))
>
> class Userskill(models.Model):
> who = models.ForeignKey(User, verbose_name=_('Person'))
> name = models.ForeignKey(Skill, verbose_name=_('Skill'))
>
> I tried a lot of things but should miss a point somewhere. My last
> attempt is something like based on :
>
> user = User.objects.get(pk=1)
> user_skill = user.userskill_set.all().select_related()
> for k in user_skill:
> p = k.name
> print p.domain
>
> {# -- Skills -- #}
> {% if user_skill %}
> <div id="skill">
> <strong>{% trans "Skills" %}</strong>
> <ul>
> {% for item in user_skill %}
> {% ifchanged %}
> <li>{{ item.name.domain }}
> {% endifchanged %}
> <ul>
> <li class="{{ item.level }}"><img
> src="/static/img/{{item.progress}}.png" alt="{{
> item.get_progress_display }}" /><a href="{{ item.name.url }}"
> class="skill" rel="tag">{{ item.name }}</a></li>
> </ul>
> </li>
> {% endfor %}
> </ul>
> </div>
> {% endif %}
>
> This solution works except that I have a side effect with a <ul></ul>
> that I do not wish.
You don't mention which of the "ul" elements is coming out empty, but I
guess this happens in the case where user_skill is empty. So wrap that
section in an {% if user_skill %} template tag (wrap it around the <ul>
and close it after the closing </ul>).
Regards,
Malcolm
--
I've got a mind like a... a... what's that thing called?
http://www.pointy-stick.com/blog/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---