I'm running Django 1.7.
I have the following model form:
class DeckCreateForm(forms.ModelForm):
csv_file = forms.FileField(required=False)
class Meta:
model = Deck
fields = ['title', 'description']
Notice that the file field is not part of the model (and I would like to keep it this way). This file field is meant to provide an alternative means of constructing the model Deck.
I would like to know how to access the uploaded file. I looked in my media directory but it is not there. I tried adding a "upload_to" to the csv_file constructor but get an error:
TypeError: __init__() got an unexpected keyword argument 'upload_to'
EDIT:
I would like to know how to get this to work with a generic class based create view which makes use of the above model form - in views.py I have:
class DeckCreateView(CreateView):
model = Deck
form_class = DeckCreateForm
template_name = 'deck_create.html'
Specifically, how do I modify something like http://docs.djangoproject.com/en/1.7/topics/http/file-uploads to work with the above class based view. My urls.py file:
urlpatterns = patterns(
...
url(r"^deck/create/$", views.DeckCreateView.as_view(), name="deck-create"),
...
)
Is there a method which I can override in DeckCreateView to handle the file upload?