views:

145

answers:

1

I am currently using Django forms with the Google App Engine and I have a model which is as follows:

class Menu(db.Model):
    name = db.StringProperty(required=True)
    is_special = db.BooleanProperty()
    menu_items =  db.ListProperty(MenuItem)

I have a MenuForm which is the following:

class MenuForm(djangoforms.ModelForm):
    class Meta:
        model = Menu
        exclude = ['added_by','menu_items']

When I run this I get the following error:

Exception Type:     ValueError
Exception Value:    Item type MenuItem is not acceptable

I want to crate the form and have it omit the menu_items property as for one I don't think there is an in built control for the multiple choice, like a group of check boxes. Either way I cannot understand with this property in the exclude items why it is throwing this error.

TIA

Andrew

+3  A: 

Your problem comes well before the "create a form" task begins: ListProperty does not allow a list of model entities (although I can't find this clearly documented in the app engine docs, I'm still looking in the docs for a good, clear, unambiguous statement about that). Try changing it into (say) a list of strings, and you'll see everything works (I believe a dropdown is what you get if you don't exclude such a property).

Edit: found the spot in the docs where the issue is mentioned, although it's quaintly phrased -- quoting with added emphasis:

The list can contain values of any of the value types supported by the datastore.

...point is, you can have in the list objects of any of the value types... not reference ones, i.e., entities that are instances of some model.

Could you use a list of key strings, instead...?

Alex Martelli
Thank you, that would explain things.!! :-) Thanks for your time!
REA_ANDREW
You don't need a list of key strings - db.Key is a valid value type for a list property.
Nick Johnson
@Nick, thanks for the important info -- I hadn't realized that Key was "a value type supported by the datastore" (this will let me simplify my code in a couple of spots).
Alex Martelli