Hmm...I'm not sure how to use your suggestion. Maybe if I make my
question more specific it will help.

My html looks something like this:

<form method="POST" action="." enctype="multipart/form-data">
  Title: <input type="text" name="title"/>
  Text: <input type="text" name="txt"/>
  Image: <input type="file" name="imgfile"/>

  <input type="submit"/>
</form>

If I were writing every field, every time, my python (Django) would
look something like this:

if request.POST:
   formitem = TestModel()
   formitem.title = request.POST.get('title', '')
   formtem.txt = request.POST.get('txt', '')
   if request.FILES['imgfile']:
       formitem.img =  request.FILES['imgfile'].read()

   formitem.put()

However, if the user only enters/changes, say, the txt field on the
form I only POST the txt field to the server. I don't send all the
fields. My POST only has data for txt. If I use the code above on an
existing entity, it will erase the title property (formitem.title).

Is there an elegant way to write only the txt element to the txt
property? If we were working with SQL, we could do something roughly
like this:

dctPOST = request.POST
strSQL1 = "INSERT INTO testmodel ("
strSQL2 = "VALUES ("
for k, v in dctPOST.iteritems():
    strSQL1 += ", %s" % (k)
    strSQL2 += ", %s" % (v)

strSQL = strSQL1 + ") " + strSQL2 + ")"

Then execute the SQL. On other RDBMS platforms, there would probably
be a collection of fields that we could reference like this: table
(strFieldName)=value.

Basically, I want write access to model properties by name or some
other dictionary-like reference (Model.properties() is read only). Am
I approaching this problem the wrong way on appengine, or is this a
limitation?

Thanks,
David

On Jan 24, 7:33 am, kang <areyouloo...@gmail.com> wrote:
> You can get the form data through
> self.request.get("name")
>
> and give the object proper property.
>
> for example, in the html
>
> <form action="/submit" method="post">
> <input name="a">
> <input name="b">
> <input type="submit" value="Post">
> </form>
>
> in the server side, you write,
>
> class Submit(webapp.RequestHandler):
>     def post(self):
>         a = self.request.POST.get('a')
>         b = self.request.POST.get('b')
>         object = Object()
>         object.a=a
>         object.b=b
>         object.put()
>
>
>
> On Fri, Jan 23, 2009 at 4:48 PM, David Kamenetz <kamene...@yahoo.ca> wrote:
>
> > Has anyone tried to dynamically select which properties they want to
> > write to an entity on appengine? For example:
>
> > I have a web form with 5 fields, and any given user will fill out some
> > subset of those fields. I POST only the fields with data to the server
> > (e.g. Fields 1,2,4). On the server side, how do I elegantly write only
> > properties 1,2, and 4? The Model class has a function that returns a
> > dictionary of property names (Model.properties()), but how would I use
> > it to select property names?
>
> > In SQL, I would build an INSERT or UPDATE statement by matching the
> > fields POSTed against the Model.properties() dictionary. I read trunk/
> > google/appengine/ext/db/init.py which seemed to confirm that there is
> > no way to refer to the properties as a group. Am I approaching this
> > the wrong way? Anyone know of a workaround?
>
> --
> Stay hungry,Stay foolish.
--~--~---------~--~----~------------~-------~--~----~
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 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to