python - Cannot access members of UserProperty in code -


i'm new google apps , i've been messing around hello world app listed on google app site. once finished app, decided try expand on it. first thing added feature allow filtering of guestbook posts user submitted them.

all have changed/added handler wsgiapplication , new class handler. model same, i'll post reference:

class greeting(db.model):     author = db.userproperty()     content = db.stringproperty(multiline = true)     date = db.datetimeproperty(auto_now_add=true) 

using django template changed line displays authors nickname from:

<b>{{ greeting.author.nickname }}</b> wrote: 

to:

<a href="/authorposts/{{ greeting.author.user_id }}">   {{ greeting.author.nickname }} </a></b> wrote: 

the issue i'm having inside python code cannot access "greeting.author.nickname", or of other properties, such "user_id". accessible django template, code listed above template works , correctly creates link author displaying nickname.

i using url mapping based on authors (a userproperty) property "user_id". trying find way can filter datastore using user_id criteria. i've tried directly applying filter query, i've tried pulling records , iterating through them , use if...else clause.

i know value store datastore, because django template shows it, have use filter criteria?

when querying greeting model, cannot filter on fields within greeting.author (e.g., greeting.author.nickname). in sql, done doing join on greeting , user tables. however, in gae can query properties directly included on model querying.

since author db.userproperty, can filter user this:

# fetch 10 greetings current user user = users.get_current_user() results = greeting.all().filter('author =', user).fetch(10) 

to filter on other fields within author, need denormalize greeting model - i.e., add copies of fields in author want able filter greeting on. example, if wanted filter author.nickname, add author_nickname field greeting model (and keep value date author.nickname):

class greeting(db.model):     author = db.userproperty()     author_nickname = db.stringproperty() # denormalization (copy of author.nickname)     content = db.stringproperty(multiline = true)     date = db.datetimeproperty(auto_now_add=true) 

if add sort of denormalization model, might helpful use nick johnson's aetycoon library make author_nickname update whenever author updated (just don't have manually enforce relationship).


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -