[Answer]-How to assign a file to the FileField in Django?

1👍

Change

class File(models.Model):
    user = models.ForeignKey(User)
    src = models.FileField(upload_to="src")

to:

class UserFile(models.Model):  # for example
    user = models.ForeignKey(User)
    src = models.FileField(upload_to="src")

and then create it like this:

files = UserFile.objects.create(src=djangofile, user=user)

from django.core.files import File is conflicting with from yourapp.models import File

One example on using FileFields.

Leave a comment