﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32243	Clarify docs on manually setting and saving a FileField.	Gordon Wrigley	Joshua Massover	"The documentation talks about how to set a filefield on a new object and how to set a filefield using a form but I couldn't find anything that talked about how to directly set a filefield on an existing object.
https://docs.djangoproject.com/en/3.1/topics/http/file-uploads/#handling-uploaded-files-with-a-model

Maybe those docs could use some extra detail on how you can set an existing file field by either assigning a ContentFile (with a name) to the field and saving the instance, or by calling save on the field and passing a ContentFile and a name. And particularly how the name is required in both cases and will be passed through upload_to.

Further figuring this out for myself was substantially complicated by the following behaviour:

{{{
In [24]: e=MyModel.objects.first()

In [25]: e.my_file
Out[25]: <FieldFile: None>

In [26]: e.my_file=ContentFile(content=b""fred"")

In [27]: e.save()

In [28]: e=MyModel.objects.first()

In [29]: e.my_file
Out[29]: <FieldFile: None>

In [30]: e.my_file=ContentFile(content=b""bob"", name=""bob.txt"")

In [31]: e.save()

In [32]: e=MyModel.objects.first()

In [33]: e.my_file
Out[33]: <FieldFile: files/5bc2fe4c-4262-4134-9397-c740de5a7edf/bob.txt>

In [34]: e.my_file.open().read()
Out[34]: b'bob'
}}}

Particularly 26-29 where setting the filefield to a ContentFile with no name and then saving is effectively just ignored with no error.
Is this expected behaviour?"	Cleanup/optimization	closed	Documentation	3.1	Normal	fixed		Joshua Massover	Ready for checkin	1	0	0	0	0	0
