views:

53

answers:

2

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?

A: 

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(),
    } 
tomlog
Trying this, I am getting an error stating FileInput is not defined.
Wes
@Wes: it was probably missing the namespace (I assume you called the django.forms import djangoforms). I have updated my example.
tomlog
A: 

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

Wes