How do I use a ListProperty(users.user) in a djangoforms.ModelForm on Google AppEngine?
I have been looking around a bit for info on how to do this. Essentially I have a Model:
class SharableUserAsset(db.Model):
name = StringProperty()
users = ListProperty(users.User)
My questions are:
- What is the best way to associate users to this value where they are not authenticated, visa vi invite from contacts list etc.?
- Is there a reasonable way to present a list control easily in a djangoforms.ModelForm?
- Once a user logs in I want to be able开发者_开发技巧 to check if that user is in the list for any number of SharableUserAsset class "records", how do I do that?
- Does user evaluate as a match to an email address or is there a way to look up a valid user against an email address?
In a query, comparing a list property to a value performs the test against the list members: list_property = value tests if the value appears anywhere in the list
http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#ListProperty
So to find all the SharableUserAsset
s associated with the current user just query like:
user = users.get_current_user()
assets = SharableUserAsset.gql("WHERE users = :1", user)
Here's another reference dealing with ListProperty
objects.
An App Engine User
object contains an email address, and the email address can be retireved using the .email()
method.
精彩评论