Hi Tomas, I have not read the previous emails, so please excuse me if
I'm misinterpreting something. I'll comment on what you said on the
last email only.

> I have tried with <a href="{{ category.slug }}/{{ project.slug }}"> but
> I think I need to write a new function inside views.py in my
> "portfolio" app, that will bring out that category slug, because it's
> not rendring out the category slug now.

That is because you are not passing any 'category' variable to the
template, but you don't need to. What you need to do is something like
this:
<a href="/portfolio/{{ project.category.slug }}/{{ project.slug }}">

You access the category of the current project with
'project.category'. I am assuming here that in your models you defined
a ForeignKey to Category in your Project model, i.e. that a Project
belongs to a Category, like this:


> My portfolio urls looks like this now (with corrected typos)
>
> # Portfolio:
>     (r'^portfolio/$', 'myproject.portfolio.views.index'),
>     (r'^portfolio/(?P<category_slug>\d+)/$',
> 'myproject.portfolio.views.list'),
>     (r'^portfolio/(?P<category_slug>\d+)/(?P<project_slug>\d+)/$',
> 'myproject.portfolio.views.detail'),

The urls you see there are nothing more than regular expressions. In a
regular expression you can match a single digit with the expression
'd', and you can match one or more digits by putting the plus sign
after the 'd' ( ej. 'd+').

But in your case you need to match words, not digits. To match a word
you need to match one or more alphanumeric characters. The expression
for an alphanumeric character is 'w', to match one or more you put the
plus sign after it: w+.

Your urls could look like this:
(r'^portfolio/(?P<category_slug>\w+)/$', 'myproject.portfolio.views.list'),
(r'^portfolio/(?P<category_slug>\w+)/(?P<project_slug>\w+)/$',
'myproject.portfolio.views.detail'),

With the above urls you can match urls like /portfolio/web/school/,
where web is the category and school is the slug of the project. But
there's a problem. If your category or project slug contains two or
more words, those words will be separated by a - (hyphen) character.
For example, the url /portfolio/web/school-portal/ will not be matched
by the above urls.

You need to include the hyphen sign in your regular expression. To do
that you need to enclose the 'w' and the '-' in brackets and put the
plus sign after the closing bracket like this:

(r'^portfolio/(?P<category_slug>\[-w]+)/$', 'myproject.portfolio.views.list'),
(r'^portfolio/(?P<category_slug>\[-w]+)/(?P<project_slug>\[-w]+)/$',
'myproject.portfolio.views.detail'),

The above urls will now correctly match a path like /portfolio/web/site-portal/



> # Create your views here.
> def index(request):
>     latest_project_list = Project.objects.all().order_by('-created')
>     return render_to_response('portfolio/index.html',
> {'latest_project_list': latest_project_list})
>
> def list(request, category_slug):
>         category_slug_list = Category.objects.all()
>         return render_to_response('portfolio/index.html',
> {'category_slug_list': category_slug_list})
>

I see that you are using the same template (index.html) in both views.
Is that what you intended?

Also, the list() view is supposed to list the projects under the
specified Category. I'm guessing that what you want is to get the
Category that correspond to the specified category_slug and then list
the projects that belong to that category. In that case I would change
your list() view like this:

def list(request, category_slug):
        # Get the category and the projects that belong
        # to this category.
        category = Category.objects.get(slug=category_slug)
        projects = category.project_set.all()

        return render_to_response('portfolio/category_projects.html',
                {'category':category, 'projects': projects}
        )


And the portfolio/category_projects.html would look like this:

<h1>{{ category }}</h1>
<h2>Projects in this category:</h2>
<ul>
{% for pro in projects %}
<li><a href="/portfolio/{{ category.slug }}/{{ pro.slug }}/">{{
pro.title }}</a></li>
{% endfor %}
</ul>


As for the index.html,
>
> <h2>Projects</h2>
>
> {% if latest_project_list %}
>     <ul>
>     {% for project in latest_project_list %}
>         <li><a href="{{ category.slug }}/{{ project.slug }}">{{
> project.title }}</a></li>
>     {% endfor %}

Change this:
<a href="{{ category.slug }}/{{ project.slug }}">
with this:
<a href="/portfolio/{{ project.category.slug }}/{{ project.slug }}">


I hope this makes things clearer.


Cheers!
Jorge

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

Reply via email to