views:

16

answers:

2

My Model

class Player(models.Model):
    player_name = models.CharField(max_length=50)
    player_email = models.CharField(max_length=50)

def __unicode__(self):
    return self.player_name

My Root urls.py

urlpatterns = patterns('',
    (r'^kroster/', include('djangosite.kroster.urls')),
    (r'^admin/(.*)', admin.site.root),
)

My kroster urls.py

from djangosite.kroster.models import Player

info_dict = {
    'queryset': Player.objects.all(),
}

urlpatterns = patterns('',
    (r'^$', 'django.views.generic.list_detail.object_list', info_dict),
    (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
)

My player_list.html template

<h1>Player List</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<ul>
{% for player in object.player_set.all %}
<li id="{{ player.id }}">{{ forloop.counter }} .)&nbsp;&nbsp;{{ player }}</li>
{% endfor %}
</ul>

Sadly my template output is this.

<h1>Player List</h1>
<ul>

</ul>

Apologies if this is a stupid mistake. It has to be something wrong w/ my template.

A: 

Your template should be something like this:

<h1>Player List</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<ul>
{% for player in object_list %}
<li id="{{ player.id }}">{{ forloop.counter }} .)&nbsp;&nbsp;{{ player }}</li>
{% endfor %}
</ul>
WoLpH
Not only does it work, but it simplifies a few misunderstandings i had. Thank you.
Kirby
+1  A: 

The variable for list view (unless otherwise specified) is object_list.

For detail it's object. Also, you'll need another template for the detail view. By default the template name is: <app_label>/<model_name>_detail.html (unless you specify it differently)

All here:

http://docs.djangoproject.com/en/dev/ref/generic-views/

ariddell
i read the documentation i must have missed it. Thank you.
Kirby