Django Form field in Initial Data: requires a FieldFile instance

I just followed the source back from django’s ClearableFileInput all the way to django’s model field magic… all the way to a little thing called FieldFile.

FieldFile can be faked with these minimum attributes:

from django.core.files.storage import default_storage

class FakeField(object):
    storage = default_storage

fieldfile = FieldFile(None, FakeField, file_path)

form = SomeForm(initial={'filefield': fieldfile })

WHEW!

2 thoughts on “Django Form field in Initial Data: requires a FieldFile instance

    1. Hey I might take you up on that.. sounds amazing. I’m glad it helped! This is a super obscure post. I think I was working on re-rendering a large dynamic form as it was filled 😛

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s