Skip to content

Instantly share code, notes, and snippets.

@rixx
Created August 2, 2017 11:44
Show Gist options
  • Save rixx/f5f0b25f6b1bf245f97d66ce25665646 to your computer and use it in GitHub Desktop.
Save rixx/f5f0b25f6b1bf245f97d66ce25665646 to your computer and use it in GitHub Desktop.
Django Url Considerations
from django.db import models
from urlman import NamedUrls
class Event(models.Model):
code = models.CharField(max_length=20)
class urls(NamedUrls):
base = 'orga:event.list'
detail = 'orga:event.view', {'event': self.code}
class Question(models.Model):
event = models.ForeignKey(to=Event, on_delete=models.CASCADE)
class urls(NamedUrls):
base = 'orga:event.questions.list', {'event': self.event.code}
detail = 'orga:event.questions.view', {'event': self.event.code, 'pk': self.pk}
from django.conf.urls import include, url
import .views
orga_urls = [
url('^event/$', views.EventList.as_view(), name='event.list'),
url('^event/(?P<event>\w+)/', include([
url('^$', views.EventDashboardView.as_view(), name='event.view'),
url('^questions$', views.QuestionList.as_view(), name='event.questions.list'),
url('^questions/(?P<pk>[0-9]+)$', views.QuestionDetail.as_view(), name='cfp.question.view'),
])
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment