Re: Best way to access 'request' in pre_save

2010-02-19 Thread Dougal Matthews
On 19 February 2010 10:27, Paul Stone wrote: > > > That's fine for one or two models. But what if I want to do this for a > > > number of models, in every view? What's the best way to do that > > > without code repetition? > > > > Using a ModelForm? > > > > http://docs.djangoproject.com/en/dev/to

Re: Best way to access 'request' in pre_save

2010-02-19 Thread Paul Stone
> > That's fine for one or two models. But what if I want to do this for a > > number of models, in every view? What's the best way to do that > > without code repetition? > > Using a ModelForm? > > http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ Ok, I think I understand now. ModelFo

Re: Best way to access 'request' in pre_save

2010-02-19 Thread Dougal Matthews
On 19 February 2010 09:28, Paul Stone wrote: > > > Presumably you have a view which is updating this object. The view has > > access to the HttpRequest. Therefore, the easy, simple, clean and > > elegant way is... to have the view set the value of that field. So do > > that and ignore anyone who

Re: Best way to access 'request' in pre_save

2010-02-19 Thread Paul Stone
> Presumably you have a view which is updating this object. The view has > access to the HttpRequest. Therefore, the easy, simple, clean and > elegant way is... to have the view set the value of that field. So do > that and ignore anyone who tells you otherwise -- > magically/secretly/implicitly t

Re: Best way to access 'request' in pre_save

2010-02-18 Thread David De La Harpe Golden
On 18/02/10 15:55, Paul Stone wrote: I'm trying to find the best way to update a model using data from the request object (e.g request.user) before it is saved. One use case for this is updating an 'updated_by' field on a model. I've come across http://www.djangosnippets.org/sn/ippets/476 which

Re: Best way to access 'request' in pre_save

2010-02-18 Thread James Bennett
On Thu, Feb 18, 2010 at 10:55 AM, Paul Stone wrote: > I'm trying to find the best way to update a model using data from the > request object (e.g request.user) before it is saved. One use case for > this is updating an 'updated_by' field on a model. Presumably you have a view which is updating th

Best way to access 'request' in pre_save

2010-02-18 Thread Paul Stone
I'm trying to find the best way to update a model using data from the request object (e.g request.user) before it is saved. One use case for this is updating an 'updated_by' field on a model. I've come across http://www.djangosnippets.org/snippets/476/ which suggests one way of doing this. What do