1
0
Fork 0

Links to artist pages now uses slugs and not internal ID

This commit is contained in:
Shgck 2015-05-02 14:28:07 +02:00
parent 68df3de4a7
commit d36d457789
3 changed files with 6 additions and 6 deletions

View file

@ -11,9 +11,9 @@ admin.autodiscover()
urlpatterns = patterns("",
url(r"^$", label.views.home, name = "home"),
url(r"^artists/$", "label.views.artists", name = "artists"),
url(r"^artists/(?P<aid>\d+)$", "label.views.artist", name = "artist"),
url(r"^artists/(?P<slug>\S+)$", "label.views.artist", name = "artist"),
url(r"^releases/$", "label.views.releases", name = "releases"),
url(r"^releases/(?P<rid>\d+)$", "label.views.release", name = "release"),
url(r"^releases/(?P<tag>\S+)$", "label.views.release", name = "release"),
url(r"^admin/", include(admin.site.urls)),
)

View file

@ -13,7 +13,7 @@
{% for artist in artists %}
<span class="artist">
<a href="{{ artist.id }}">
<a href="{% url 'artist' artist.slug %}">
<img src="{{ MEDIA_URL }}{{ artist.image }}" alt="" /> <br />
{{ artist.name }}
</a>

View file

@ -1,4 +1,4 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404, render
from label.models import Artist, Release
import label.tools as tools
@ -14,8 +14,8 @@ def artists(request):
return render(request, "label/artists.html", context)
def artist(request, aid):
artist = Artist.objects.get(id = aid)
def artist(request, slug):
artist = get_object_or_404(Artist, slug = slug)
releases = artist.release_set.all()
context = { "artist": artist, "releases": releases }
return render(request, "label/artist.html", context)