Denya wrote:
> Thank you for idea about initial!
> 
> code starting at line 803 in google.appengine.ext.db.djangoforms is from 
> save() method.
> 'continue' statement there means that if you are editing data and 
> key_name passed, form processor must not try to change key_name in db, 
> 'cause it's impossible :)

The code on line 803 is correct, at update time within the form class 
the key_name must be ignored.

> So, my question -- is it right behaviour? Or may be developers forget, 
> that the need to fill field by real data from db?...

Before the Form object can be created to process an update, you first 
have to fetch an instance of the existing object from the datastore. You 
need the key_name at this point.

If you look at the article describing how to use Django forms 
(http://code.google.com/appengine/articles/djangoforms.html), although 
it doesn't cover the key_name case specifically, the corresponding case 
when using an id passes the id as a hidden form parameter, the same 
approach could/should? be used with the key_name.

Having said that, it seems like a pretty simple fix to initialise the 
key_name field when the instance is passed to the form object and it I 
agree from the conversation you've just had that it seems like the 
expected behaviour. I cannot recall if there was a specific reason why 
this wasn't done when the key_name functionality was added. Maybe it was 
forgotten as you suggest.

In any case I've attached a patch that I believe will fix the issue, it 
is basically using the initial hack Jeseja identified but within the 
Form initialiser code. I haven't tested it thoroughly so use at your own 
risk.

If it does turn out to fix the issue you are seeing it would be good if 
you could open a new issue in the tracker, then let me know the issue 
number and I'll see what I can do about getting this fixed in the next 
SDK release.

Cheers

Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

--- djangoforms.py.orig	2008-11-26 18:33:03.067712000 +0000
+++ djangoforms.py	2008-11-26 18:31:43.511350000 +0000
@@ -751,6 +751,8 @@
         if opts.exclude and name in opts.exclude:
           continue
         object_data[name] = prop.get_value_for_form(instance)
+      if "key_name" in self.base_fields:
+        object_data["key_name"] = instance.key().name()
     if initial is not None:
       object_data.update(initial)
     kwargs = dict(data=data, files=files, auto_id=auto_id,

Reply via email to