Django rest framework fileupload

Hi guys

I am very new to python and django. I am going through the tutorial on their website, which as been pretty good so far and all is very easy to understand. I am just struggling with something. I need my api to handle file uploads. I have my model setup like this:

models.py:

class Document(models.Model):
	fileData = models.FileField(upload_to='documents/%Y/%m/%d')
	created = models.DateTimeField(auto_now_add=True)

views.py:

class DocumentList(generics.ListCreateAPIView):
	"""List all documents on server and create new"""
	queryset = Document.objects.all()
	serializer_class = DocumentSerializer
	permission_classes = (permissions.IsAuthenticated,)

Now all the file upload and listing stuff is working perfectly. But now I want add columns for the file meta data. For eg. Filesize, original filename, etc. Creating the columns in the model and database is easy, that is no problem.

My question is, where do I put code to actually get this data from the file? I cannot seem to find anything online around this. Does it go in my serializer class? Any help or examples will be much appreciated.

Thanks

You are free to organise your Python code however you want generally in Django except in a few places where there are expectations on how things are supposed to be set up.

You can also override the perform_update() method in your view to read data from the serializer, as long as the serializer retains the file information. It should, if set up properly and the data is sent (via POST with multi-part) properly. That is, Django’s request.FILES list.

Cool. Thanks for the reply. Those url’s will come in handy