Changes between Version 3 and Version 4 of GenerateGenericURLs
- Timestamp:
- Jun 24, 2006, 5:43:07 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GenerateGenericURLs
v3 v4 1 = Generate Generic URLs = 2 1 3 Here's a little function I wrote to generate a standard set of URL mappings I use with generic views. It takes a list of tuples that each contain the name to use for the url and the model class that represents it. This function generates generic views for listing, viewing details, adding, editing and deleting objects for the given model. For example: 2 4 3 5 {{{ 6 #!python 4 7 make_url_list([('widget', Widget)]) 5 8 }}} … … 8 11 9 12 {{{ 13 #!python 10 14 ^/widget/$ # will list all widgets 11 15 ^/widget/(?<object_id>\d+)/$ # will give details for a specific object … … 18 22 19 23 {{{ 24 #!python 20 25 def make_url_list(input, prefix=''): 21 26 l = [] … … 49 54 50 55 {{{ 56 #!python 51 57 tup = tuple(make_url_list(input,prefix='/prefix_if_needed')) 52 58