Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to query for a Computed Property inside a Structured Property in GAE Python
    primarykey
    data
    text
    <pre><code>class Name_score(ndb.Model): def get_value_of_name(self, name, date): # concatenate "X" and date before returning return_text = "X"+name+str(date) return return_text date = ndb.DateTimeProperty() name = ndb.StringProperty() # Computed values name_value_computed = ndb.ComputedProperty(lambda e: e.get_value_of_name(e.name, e.date)) class Activity_db(ndb.Model): # contains many properties # removed the not relevant ones here name_set = ndb.StructuredProperty(Name_score, repeated=True) hobby = ndb.StringProperty() </code></pre> <p>There are many entries in the NDB. I want to get the records where on particular dates, the "name_value_computed" matches the data provided in the query.<br> To query for all such entries with specific "name_value_computed" and "date" value(example below), what would be the query. </p> <p>Example(algorithm for condition):<br> ("hobby" is "tennis") AND ((if on "date" "18/01/1900", "name_value_computed" is "XJohn18/01/1900") OR (if on "date" "22/04/1910", "name_value_computed" is "XBran22/04/1910"))<br> Is the below one correct: </p> <pre><code>date_1 = datetime.strptime("18/01/1900", '%d/%m/%Y') name_computed_value_1 = "XJohn18/01/1900" date_2 = datetime.strptime("22/04/1910", '%d/%m/%Y') name_computed_value_2 = "XBran22/04/1910" qry_1 = Activity_db.query(ndb.OR(Activity_db.name_set==Name_score(date=date_1, name_value_computed=name_computed_value_1), Activity_db.name_set==Name_score(date=date_2, name_value_computed=name_computed_value_2)), Activity_db.hobby=="tennis") record_list = qry_1.fetch() </code></pre> <p>I got the below error: </p> <pre><code>File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 2745, in __init__ self._set_attributes(kwds) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 2791, in _set_attributes prop._set_value(self, value) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\ndb\model.py", line 2612, in _set_value raise ComputedPropertyError("Cannot assign to a ComputedProperty") ComputedPropertyError: Cannot assign to a ComputedProperty </code></pre> <p>I referred <a href="https://developers.google.com/appengine/docs/python/ndb/queries#filtering_structured_properties" rel="nofollow">this section</a> of the Google Python GAE page </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload