Created
August 2, 2017 11:44
-
-
Save rixx/f5f0b25f6b1bf245f97d66ce25665646 to your computer and use it in GitHub Desktop.
Django Url Considerations
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
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} |
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
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