problem with filtering in a referenceproperty dropdown - Django
I have the following problem. I have a contact class that different users can tag with their own topics:
class Contact(db.Model):
contact_date = db.DateProperty(auto_now_add=True)
remarks = db.TextProperty()
topic = db.ReferenceProperty(Topic)
class Topic(db.Model):
topic = db.StringProperty(required=True)
description = db.TextProperty()
owner = db.ReferenceProperty(User, collection_name='topic_set')
def __unicode__(self):
return '%s' % (self.topic)
In the form for this i want to only show the Topics for a certain user
class ContactForm(forms.开发者_StackOverflowModelForm):
def __init__(self, user_filter, *args, **kwargs):
self.base_fields['topic'].queryset = Topic.all().filter('owner
= ', user_filter)
super(ContactForm, self).__init__(*args, **kwargs)
I then call the ContactForm from the view as follows:
form = ContactForm(user_filter = request.user.key())
This all works as expected. However when I submit the form I get:
Caught an exception while rendering: Unsupported type for property :
<class 'django.http.QueryDict'>
Am I doing something wrong? Is this some problem with appengine django implementation? Peter
A Contact can have one Topic and one Topic only. As you explained:
I have a contact class that different users can tag with their own topics
I would move the ReferenceProperty
to the Topic class:
class Topic(db.Model):
contact = db.ReferenceProperty(Contact)
Now one Contact can have multiple Topics.
Your exception comes from assigning a property with a Request Query Dictionary. This probably comes from declaring user_filter
as an argument, but using it as a keywords argument.
It should be:
form = ContactForm(request.user.key())
But as stated above, first you should revise your models.
精彩评论