I have two models like this:
class A(models.Model):
attachment = FileField(upload_to='a')
class B(models.Model):
attachment = FileField(upload_to='b')
I have instance of A model:
a = A.objects.get(pk=1)
I need to create instance of B model, with file copied from a instance.
How can I do that?
I was trying something like this, but it is not working:
from django.core.files import File
B.objects.create(attachment=File(open(a.attachment.path, 'rb')))
It strange thing. Now the way I tryed before works perfectly, without any errors.
Maybe I missed something at the first time. So it works: