Django's ImageField
lets me store a file object in it using a normal assignment.
from urllib import request
from django.db import models
from django.core.files.base import ContentFile
class Customer(models.Model):
logo = models.ImageField()
customer.logo = ContentFile(request.urlopen(url), 'image.png')
Now I want to inherit a custom field type from ImageField
. It takes an URL as a plain string instead of a file object for assignment. Internally, it should fetch the image and assign it to it's base class, right as in the manual example above.
from django.db import models
class UrlImageField(models.ImageField):
def __set__(self, instance, value):
super() = ContentFile(urllib.request.urlopen(value), 'image.png')
Therefore, I need to call the assignment operator on the ImageField
base class. How can I do that in Python?