views:

215

answers:

1

am designing a feed system for users.

so i have:

class User(db.Model):
  name = db.StringProperty()
  list_of_keys = db.StringListProperty()

class Feed(db.Model):
  event = db.StringProperty()
  timestamp = db.DateTimeProperty()

# I created 10 feed entities

# assuming i already have my 10 feed entities, I take their keys and put into this list
list_of_keys = ["key1","key2","key3",.........."key10"]

if I use

db.key(list_of_keys)

I get all the entities. no problem. So it works when all of the keys are present ( ie: it works if the entities are still in the datastore)

But if I delete even one of the entities, then db.key() returns a NoneType.

any suggestions on how to go about this?

PS: i'm trying to avoid using ReferenceProperty in my feed system, cos I think it might get messy

if you still suggest that I use ReferenceProperty, here are my goal(s):
1. Each feed entity should "belong" to more than one user.
2. Each user can have up to 20 feeds max.
3. New feeds will replace the old ones based on timestamp.

would love to hear your thoughts/solutions.

+2  A: 

Assuming you have the strings that encode the actual keys (as opposed to just the keynames or something else again), first make the list of strings (that you so peculiarly and confusingly choose to call instead a list of keys though it's clearly and obviously a list of strings instead!) back into a list of Keys:

thekeysforreal = [db.Key(k) for k in list_of_keys]

Now, db.get(thekeysforreal) will do its job, per the docs:

If a list of Keys is provided, the return value is a corresponding list of model instances, with None values when no entity exists for a corresponding Key.

Alex Martelli
i did that, still didn't work out.i still get a Nonetype error when one of the entities were deleted. (although the key string still exists in my list)
fooyee