Python Bookshelf tutorial (flexible environment): how to create new properties and entities within project?

55 views
Skip to first unread message

Ridley Jones

unread,
Nov 30, 2018, 4:44:47 PM11/30/18
to Google App Engine
Hi,

Newbie here.  I'm working through this tutorial and am on this page: https://cloud.google.com/python/getting-started/using-cloud-datastore.  Obviously I'm within the 2-structured-data folder of the tutorial project.

I've completed the tasks in that page of the tutorial, successfully.  To help me get how the parts fit together and how to build on the structures in the project files and just generally understand this environment better, I wanted to 1. add a new book property (with a certain datatype, integer maybe), and then 2. create a new entity type that would be CRUDable within the project.

I found that simply adding a new div to the form.html page flexibly (as promised) created a new property within Datastore that I was able to edit: 

  <div class="form-group">
    <label for="description">Anotherone</label>
    <input type="number" name="newprop" id="newprop" class="form-control" value="{{book.newprop}}"/>
  </div> 

Fine--I'm pleased with that.  However, what I don't see is how to ensure that the actual data being uploaded is in fact non-string.  (In the tutorial, the "published date" property was also uploaded as string).  If I were going to edit the model_datastore file or the crud file, how would I do this to ensure that the newprop property got inserted as numerical? The documentation briefly says that datastore doesn't enforce typing, that the application is responsible for that, but how would one modify these specific tutorial files in order to do that?

My next question is how to create a new entity type within this tutorial.  Do I need to create another app folder, or can I modify (as I said) the crud or model_datastore files here to accommodate another potential entity?  If I wanted to create a, for example, /publishers entity type and page?

Thanks so much for your help with what I'm sure is very basic stuff!

Katayoon (Cloud Platform Support)

unread,
Dec 4, 2018, 7:50:36 PM12/4/18
to Google App Engine
Hi Ridley,

As explained in the code review section, the data submitted via the HTML form is passed to the "add" handler in the crud.py to create the entity. Apparently the data coming from the HTML isn't passes in JSON and all are passed as string. That is why you see Type String for all properties. 

Both your questions are technical ones and you may post your questions separately in Stack Overflow. Note that Google Groups are reserved for general discussions on Google Cloud platform-end products and not for technical questions. 
Reply all
Reply to author
Forward
0 new messages