Wes
Wes

Reputation: 1854

Google App Engine django model form does not pick up BlobProperty

I have the following model:

class Image(db.Model):
    auction = db.ReferenceProperty(Auction)
    image = db.BlobProperty()
    thumb = db.BlobProperty()
    caption = db.StringProperty()
    item_to_tag = db.StringProperty()

And the following form:

class ImageForm(djangoforms.ModelForm):
    class Meta:
        model = Image

When I call ImageForm(), only the non-Blob fields are created, like this:

<tr><th><label for="id_auction">Auction:</label></th><td><select name="auction" id="id_auction">
<option value="" selected="selected">---------</option>
<option value="ahRoYXJ0bWFuYXVjdGlvbmVlcmluZ3INCxIHQXVjdGlvbhgKDA">2010-06-19 11:00:00</option>
</select></td></tr>
<tr><th><label for="id_caption">Caption:</label></th><td><input type="text" name="caption" id="id_caption" /></td></tr>
<tr><th><label for="id_item_to_tag">Item to tag:</label></th><td><input type="text" name="item_to_tag" id="id_item_to_tag" /></td></tr>

I expect the Blob fields to be included in the form as well (as file inputs). What am I doing wrong?

Upvotes: 2

Views: 623

Answers (2)

Tom van Enckevort
Tom van Enckevort

Reputation: 4198

You can use the widgets attribute to define the field type used for your blob properties:

class ImageForm(djangoforms.ModelForm):
class Meta:
    model = Image
    widgets = { 
        'image': djangoforms.FileInput(),
        'thumb': djangoforms.FileInput(),
    } 

Upvotes: 0

Wes
Wes

Reputation: 1854

I think my problem hinges on the fact that Django does not support blobs, so the BlobProperty is simply ignored when generating Django forms.

Upvotes: 1

Related Questions