0

OS Win7, GAE 1.7.6, Python 2.7.3, still learning GAE..

Working on project, which need to have input form to extend its content(name,email,phone..) with defined Key Name in Datastore, preferably to increase in define way. I have never worked with Key Name, before I always let the datastore generated automatically id.

Datastore is populated using appcfg.py tool to import data from a CSV file.

When I add a new content. Link: http://s17.postimg.org/6pfqjv6gv/Unffaftitled.png

What would be some basic example of defining a Key Name in Datastore?

That_User
  • 929
  • 2
  • 7
  • 25

4 Answers4

3

Is this what you're looking for?

class Employee(db.Model):
  first_name = db.StringProperty()
  last_name = db.StringProperty()

employee = Employee(key_name='asalieri',
                    first_name='Antonio',
                    last_name='Salieri')

employee.put()

This creates an entity with key name asalieri. You can then retrieve this entity with Employee.get_by_key_name ('asalieri').

It's the sample code from the documentation here: https://developers.google.com/appengine/docs/python/datastore/entities#Creating_an_Entity

Hope that helps!

pfalke
  • 336
  • 1
  • 9
1

According to the official docs you can map the __key__ pseudo-property to the appropriate CSV column in your bulkloader .yaml configuration file, e.g.:

transformers:
- kind: MyKind
  ...
  property_map:
  - property: __key__
    external_name: MyKeyColumn
    ...

(If you want the datastore to automatically generate the key id for you, like before, then you have to remove this property from the .yaml file.)

zengabor
  • 2,013
  • 3
  • 23
  • 28
  • bulkloader.yaml show this shema...how to achive that my next input will map to the __ key __ pseudo-property(Key Name), and not to the automatically generate key id, also to make note I'm using wtf.Form to achive input on ndb. – That_User Apr 08 '13 at 07:53
  • I am not sure about the forms framework that you are using but if you provide an integer then it will become key's ID part, and if you provide an alphanumeric string then it will become the "Key Name" part of the key. You use either an integer or a string. – zengabor Apr 08 '13 at 08:08
1

Quick Advice

Working on project, which need to have input form to extend its content(name,email,phone..) with defined Key Name in Datastore, preferably to increase in define way.

Took me like a minute or two trying to understand what you are saying.

Don't rush typing out what you want to ask without thinking.
If you want a well thought out answer from other people, try to ask the question clearly.

My Questions to You

Why do you think you need to define the Key Name manually?
What benefit do you think you are getting?

From what I can infer, you seem like you don't understand the basics of the GAE HRD Datastore.
If you don't understand the HRD datastore, you can't code effectively on GAE.

My Answer

There is no short answer to your question.
I can only recommend you to invest a couple of hours watching AND reading the following.
Then, you can make a better design decision.

  1. Watch Building Scalable Web Apps with App Engine - Google IO 2008 especially from the 28 minute mark. I would recommend watching the whole thing.
  2. Watch App Engine Datastore Under the Covers - Google IO 2008.
  3. Read Best Practices for writing scalable applications.
  4. From Mastering the datastore, I find the Modeling Entity Relationships part quite useful as well.
  5. Here is another really useful Stackoverflow Q&A -- How to think in datastore instead of Database
Community
  • 1
  • 1
stun
  • 1,684
  • 3
  • 16
  • 25
  • Will look into it, well that's the answer then, learning more about GAE HRD Datastore, if you have more relevant materials about this topic please leave them here. I know Google is my friend, but experience is the best. Thank you for your answer. – That_User Apr 09 '13 at 09:44
  • I added some more links and resources that I personally find very useful. – stun Apr 09 '13 at 14:43
0

ndb example (look for 'id' insted 'key_name'):

employee = Employee(id='asalieri',
                    first_name='Antonio',
                    last_name='Salieri')
Wagner Pereira
  • 1,050
  • 11
  • 11