Im trying to implement a gallery app in django cms.
I want urls like this: www.site-url.com/gallery/category/gallery-name
My solution is not fully working. If I go to this url http://127.0.0.1:8000/en/gallery/1001/test/ where "1001" is a category and "test" is gallery-name, I want to check if a category exist and if a gallery belongs to this category.
Next problem is, if I want to get full url of gallery with get_absolute_url()
method. My urls.py are bad implemented, so it's not working.
my urls.py:
from django.conf.urls import patterns, url
from .views import GalleryListView, GalleryDetailView
urlpatterns = patterns('',
# List View
url(r'^(?P<parent_slug>[-\w]+)/(?P<slug>[-\w]+)/$', GalleryDetailView.as_view(), name="gallery_detail"),
url(r'^$', GalleryListView.as_view(), name="gallery_list"),
)
my models.py:
class Category(Sortable): parent = models.ForeignKey('self', blank=True, null=True) name = models.CharField() slug = AutoSlugField(populate_from='name') def __unicode__(self): return self.name def get_absolute_url(self): return "#" class Gallery(Sortable): name = models.CharField() parent = models.ForeignKey(Category, blank=False, null=True) slug = AutoSlugField(populate_from='name') def __unicode__(self): return self.name def get_absolute_url(self): return reverse('gallery_detail', args=[self.pk])