I have a model similar to this:
----------------------------------
class Device(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(blank=False, maxlength=40)
#...
class Item(models.Model):
id = models.AutoField(primary_key=True)
device = models.ForeignKey(Device)
name = models.CharField(blank=False, maxlength=40)
# ...
----------------------------------
And I have use generic views to get this to the browser:
----------------------------------
device_dict = {
'queryset': Device.objects.all()
}
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list',
device_dict),
(r'^(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail',
device_dict),
----------------------------------
And now I entered various Devices and Items using Django's admin.
So far so got.
But now in the object_detail for the Device, I want to have a
list of all assigned Items. How do I do this? I tried:
----------------------------------
extra_context = {
'items': Item.objects.all(),
}
device_extra_dict = {
'queryset': Device.objects.all(),
'extra_context': extra_context,
}
and
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list',
device_dict),
(r'^(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail',
device_extra_dict),
----------------------------------
And in my device_detail.html I tried something like this:
----------------------------------
{% block content %}
<table><tr>
<td>Id</td><td>{{ object.id }}</td>
</tr><tr>
<td>Name</td><td>{{ object.name }}</td>
</tr></table>
<h2>Items</h2>
<ul>
{% for i in items %}
<li>{{ i.name }}</li>
{% endfor %}
</ul>
----------------------------------
But of course I'm always getting all items, not just the items
for the current device.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---