Parse URLs to integers

2009-09-23 Thread IanSR
Is there some trick to parse http://www.example.com/foo/42 such that "42" becomes an integer parameter to the view function, instead of a string? Right now I have to do: from my.app.views import foo urlpatterns = patterns('', (r'foo/(?P\d+)/?$', foo), ) my/app/views.py def foo(reque

urls.py to directly call method on instance of FooModel

2009-09-17 Thread IanSR
I would like tighten the link from URLs to instances of Models and have something like: import foo.FooModel urlpatterns = patterns('', (r'foo/create/?$', 'foo.FooModel.create'), (r'foo/(?P\d+)/?$', 'foo.FooModel.view'), (r'foo/(?P\d+)/edit$', 'foo.FooModel.edit'

Including username in FileField upload_to path

2009-03-26 Thread IanSR
I've spent the last few hours trying variations on upload_to for my FileField path generator get_file_path(instance,filename) that will allow me to include the username from the POST HttpRequest object. No luck. Does anyone have any suggestions on how to do this? My instance does have a "user"

Missing something obvious in auto-form generation

2009-03-13 Thread IanSR
I have a model Foo and a corresponding FooForm with the requisite inner Meta class and model=Foo. I want a url example.com/newfoo to bring up a blank form to allow the creation of a new Foo instance. It is not obvious to me how this should be done. I reckon it is something very roughly like: