GET parameters in admin "add" model page

80 views
Skip to first unread message

?manu*

unread,
May 11, 2014, 11:42:57 AM5/11/14
to django...@googlegroups.com
I noticed that django admin "add" page reads GET parameters and uses them as initial values in the form. However I was not able to pass DateTime values in this way. In particular if I try to pass a DateTime value I get a "server error". 

See http://stackoverflow.com/questions/23559771/django-admin-add-page-initial-datetime-from-get-parameters for more details. 

1. is it possible to pass DateTime values this way?

2. isn't it a bug if a user is able to generate a server error by messing with GET parameters?

thanks
E.

Russell Keith-Magee

unread,
May 13, 2014, 1:42:41 AM5/13/14
to Django Users
Hi,

On Sun, May 11, 2014 at 11:42 PM, ?manu* <emanuele...@gmail.com> wrote:
I noticed that django admin "add" page reads GET parameters and uses them as initial values in the form. However I was not able to pass DateTime values in this way. In particular if I try to pass a DateTime value I get a "server error". 

See http://stackoverflow.com/questions/23559771/django-admin-add-page-initial-datetime-from-get-parameters for more details. 

1. is it possible to pass DateTime values this way?

Yes, but not "out of the box". I've responded on the SO thread; but the short answer is that you need to override get_changeform_initial_data() in your ModelAdmin class.

2. isn't it a bug if a user is able to generate a server error by messing with GET parameters?


Not necessarily. It's only a bug if, when *using the APIs as documented*, a user is able to generate a server error by providing faulty GET arguments. Taking the extreme case of the argument - if you write a view that knowingly does divide by zero, it's not a bug in Django that the user is able to generate a 500 by visiting that view. In your case, the argument is much more subtle, but you still have code that is "wrong", and as a result, it's raising a 500.

Yours,
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages