python - App engine ndb. Query model based on Reference Property -


I have some problems in querying the object while using NDB in the AppEngine framework for I It is very new and I think I understand some important concepts wrong.

Here's what I got:

I have my model code teacher (ndb.model) from the teacher : Webapp2_extras.appengine.auth.models : User = ndb.StructuredProperty (user) ranking = ndb.FloatProperty (required = true) as you can see, from webapp 2 framework Comes. Then I try to ask some affiliate teacher. I do it like this:

  def _findTeacher (self, user): t = teacher. Curious (teacher.use == user). Fetch (1) If T: Returns T [0] Else: return Anyone   

The user coming in the form of this function comes as follows: < Pre> user_session = self.auth.get_user_by_session () user = Self.auth.store.user_model.get_by_auth_token (user_session ['user_id'], user_session ['token']) [0]

However, I get the following error:

  BadFilterError: invalid filter: non-empty repetitive property can not query for auth_ids   

I would like to know where my mistake Land and example of an app using Andibi and Vebpp 2 Eighth system will be very useful.

thanks all

to:

Although a structured property can be duplicated and a structured property may include another structured property, be careful: if one is in a structured asset, only one of them can be repeated.

The error is happening because the teacher User is a structured property that includes teachers. The user .auth_ids, which is the repetitive Structured Sprouts.

Edit (solution):

I recommend doing this:

  class teacher (ndb.model): user = ndb.KeyProperty ( User) Ranking = ndb.FloatProperty (required = true)   

Store a reference for the user. It will work for your example above, however, it also means that you can not query any user properties, such as Teacher.User.name == 'bob' .

And you will ask:

  t = teacher.query (teacher.user == user.key) .fetch (1)   

I hope it helps.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -