I have a a list that I generate using this code in a template:

{% extends "base.html" %}

{% block title %}Lobbyist by Country {% endblock %}

{% block content %}

<h2> Browse  by County </h2>

<p>Click on one of the items below to get information about the firms
</p>

<ul>

{% for county in county_list %}

<li><a href ="{{ country.get_absolute_url }}">{{ country.name }}</a></
li>

{% endfor %}

</ul>

{% endblock %}

I want to add a url and tried to use the get_absolute_url method of
model:


class Country(models.Model):
    name = models.CharField(max_length=80)
    slug = models.CharField(max_length=80)

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return "/country/%s/" % self.slug

What I'd like to do is to be able to click on an object from my list
in the template which would then go to a details page which looks like
this:


{% extends "base.html" %}

{% block title %} Ujima Project {% endblock %}

{% block content %}

Country: {{country}}

<p> This table contains all firms and individuals who lobbied on
behalf of the country.</p>

  <table>

<th>Name</th><th>Address</th><th>Client</th><th>County</th><th>Amount</
th>

{% for c in county %}
   <tr>
      <td>{{c.name}}</td>
      <td>{{c.address}}</td>
      <td>{{c.client}}</td>
      <td>{{c.country}}</td>
      <td>{{c.dollar_amount}}</td>
   </tr>

  {% endfor %}

  </table>

{% endblock %}



I already have a view that gets to the last template, but I can figure
out how to use the get_absolute_url to get their from the other
template with the list. Here is my view for the last template:
def country_detail(request, county):
    c = County.objects.get(slug=countr)
    clients= Company.objects.filter(county=c)
    return render_to_response('county/county_detail.html',{'county':c,
'client':clients})

and the url: r'^county/(?P<county>[-a-z]+)/$', county_detail),

So essentially I'd like to be able to provide hyperlinks to the
objects in the first templates that would open up the second template
when you click on it. Suggestions? Hope this is not too much code to
post.

--~--~---------~--~----~------------~-------~--~----~
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 
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