Query distinct list of choices for Django form with App Engine Datastore

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2009-02-02T14:02:55Z Indexed on 2010/04/01 11:03 UTC
Read the original article Hit count: 194

Filed under:
|
|

I've been trying to figure this out for hours across a couple of days, and can not get it to work. I've been everywhere. I'll continue trying to figure it out, but was hoping for a quicker solution. I'm using App Engine datastore + Django.

Using a query in a view and custom forms, I was able to get a list to the form but then I was not able to post. I have been trying to figure out how to dynamically add the choices as part of the Django form... I've tried various ways with no success. Help!

Below are the two models. I'd like to get a distinct list of address_id to show in the location field in InfoForm. This fields could (and maybe should) be named the same, but I thought it'd be easier if they were named different.

class Info(db.Model):
    user = db.UserProperty()
    location = db.StringProperty()
    info = db.StringProperty()
    created = db.DateTimeProperty(auto_now_add=True)
    modified = db.DateTimeProperty(auto_now=True)

class Locations(db.Model):
    user = db.UserProperty()
    address_id = db.StringProperty()
    address = db.StringProperty()

class InfoForm(djangoforms.ModelForm):
    info = forms.ChoiceField(choices=INFO_CHOICES)
    location = forms.ChoiceField()
    class Meta:
            model = Info
            exclude = ['user','created','modified']

© Stack Overflow or respective owner

Related posts about django

Related posts about google-app-engine