Skip to content

Instantly share code, notes, and snippets.

@malgorath
Last active April 28, 2016 17:51
Show Gist options
  • Save malgorath/4432176b97e5338cd231cc5668fa1898 to your computer and use it in GitHub Desktop.
Save malgorath/4432176b97e5338cd231cc5668fa1898 to your computer and use it in GitHub Desktop.
{% if links %}
{% regroup links by links.linkgroup as link_list %}
{% for l in link_list %}
<li>
<h4>{{ l.grouper }}</h4>
<ul>
{% for i in l.linkgroup %}
<li>{{ i.title }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
{% else %}
<p>We got no links!</p>
{% endif %}
from django.shortcuts import render
from links.models import Link
def index(request):
links = Link.objects.all().order_by("-linkgroup")
return render(request, 'index.html', {'links': links})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment