Last active
August 29, 2015 14:12
-
-
Save jleeothon/9929b86d08aee5066b82 to your computer and use it in GitHub Desktop.
CRUD URL Design with Python
This file contains hidden or 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
# settings.py | |
APPEND_SLASH = True | |
# projectname/urls.py | |
from django.conf.urls import include | |
from django.conf.urls import patterns | |
from django.conf.urls import url | |
import people.customers.urls | |
import stock.products.urls | |
urlpatterns = patterns( | |
'', | |
url(r'^customers/', include(people.customers.urls)), | |
url(r'^products/', include(stock.products.urls)), | |
) | |
# people/customers/urls.py | |
from django.conf.urls import include | |
from django.conf.urls import patterns | |
from django.conf.urls import url | |
from people.customers import views | |
urlpatterns = patterns( | |
'', | |
url(r'^$', views.ListView.as_view(), name='customer-list'), | |
url(r'^new/$', views.CreateView.as_view(), name='customer-create'), | |
url(r'^(?P<pk>\d+)/', include(patterns( | |
url(r'^$', views.DetailView.as_view(), name='customer-detail'), | |
url(r'^edit/$', views.UpdateView.as_view(), name='customer-update'), | |
url(r'^delete/$', views.Delete.as_view(), name='customer-delete'), | |
))), | |
) | |
# P.S. Works great on its own, works better with https://github.com/jleeothon/urlmodel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whereas a traditional way to do it could be:
The "DRYer" way is not extremely DRY either. Unless someone will make an installable module for that. It may be added to urlmodel, but I'm too busy right now. And that's arguable a good or bad idea.