I have a model for icon, which looks like this:
class Icon(models.Model):
name = models.CharField(max_length=50)
icon = models.FileField(upload_to='icons/', blank=True, null=True)
inline_svg = models.CharField(max_length=1000, blank=True)
Most of files are .svg and I want to pass into inline_svg content of corresponding file to use inline svg on front-end. How can i do that? Or maybe there is any better variants to do what I want?
Also had an idea of something like this:
class Icon(models.Model):
def svg(self):
f = open(self.icon.url)
return f.read()
name = models.CharField(max_length=50)
icon = models.FileField(upload_to='icons/', blank=True, null=True)
inline_svg = models.CharField(max_length=1000, default=svg())