Created
July 23, 2012 21:37
-
-
Save kennethlove/3166383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for area in areas %} | |
<h1>{{ area.name }}</h1> | |
<ul> | |
{% for computer in area.computers.all %} | |
<li>{{ computer.name }}</li> | |
{% endfor %} | |
</ul> | |
{% endfor % |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Area(models.Model): | |
name = models.CharField(max_length=255) | |
class Computer(models.Model): | |
name = models.CharField(max_length=255) | |
area = models.ForeignKey(Area, related_name="computers") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def areas(request): | |
queryset = Area.objects.select_related("computers").all() | |
return render_to_response(request, {"areas": queryset}, "areas.html") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So taking this one step further would look like.
models.py
areas.html
views.py