If "continents" is contex variable wich is Continent.objects.all() so:

{% for continent in continents %}
<p>
   {{continent.name}}<br/>
   <ul>
   {% for country in continent.country_set.all %}
        <li>- {{country.country_name}} ({{country.city_set.count}})</
li>
   {% endfor %}
   </ul>
</p>
{% endfor %}

But this solution produces many sql queries. Of course it can be
optimized

On 26 дек, 13:11, [EMAIL PROTECTED] wrote:
> Hi --
>
> My model have three classes:  Continent, Country, City
>
> class Continent(models.Model):
>     name = models.CharField(maxlength=60)
>
> class Country(models.Model):
>     country_name = models.CharField(maxlength=60)
>     continent = models.ForeignKey(Continent)
>
> class City(models.Model):
>     city_name = models.CharField(maxlength=60)
>     city = models.ForeignKey(Country)
>
> I want to display a page listing the countries, by continent and
> number of cities in database.
>
> -------- Sample output -----------
>
> Continent
> - Country (number of cities)
>
> Africa
>
> - Egypt (3)
> - Kenia (62)
>
> Europa
>
> - Belgium (4)
> - Germany (8)
>
> ---------- end  sample output -----------
>
> I worked through chapter 1-7 in Djangobook and sample application on
> djangoproject site. I can display a lists via generic views, tried
> REGROUP option etc.. but battle to get it working.
>
> Any ideas on where to start or link to sample will be much
> appreciated.
>
> Many Thanks
> Liam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to