Skip to content

models

django_spire.file.models

File

Bases: HistoryModelMixin

content_type = models.ForeignKey(ContentType, on_delete=(models.CASCADE), editable=False, blank=True, null=True) class-attribute instance-attribute

object_id = models.PositiveIntegerField(editable=False, blank=True, null=True) class-attribute instance-attribute

content_object = GenericForeignKey('content_type', 'object_id') class-attribute instance-attribute

file = models.FileField(max_length=500) class-attribute instance-attribute

name = models.CharField(max_length=255, default='', editable=False) class-attribute instance-attribute

type = models.CharField(max_length=255, default='', editable=False) class-attribute instance-attribute

size = models.CharField(max_length=64, default='', editable=False) class-attribute instance-attribute

related_field = models.CharField(max_length=3, null=True, blank=True, editable=False) class-attribute instance-attribute

objects = FileQuerySet.as_manager() class-attribute instance-attribute

Meta

db_table = 'django_spire_file' class-attribute instance-attribute
verbose_name = 'File' class-attribute instance-attribute
verbose_name_plural = 'Files' class-attribute instance-attribute
indexes = [models.Index(fields=['content_type', 'object_id'])] class-attribute instance-attribute

__str__

Source code in django_spire/file/models.py
def __str__(self):
    return self.name

to_dict

Source code in django_spire/file/models.py
def to_dict(self) -> dict[str, str]:
    return {
        'name': self.name,
        'url': self.file.url,
        'id': self.id
    }

to_json

Source code in django_spire/file/models.py
def to_json(self) -> str:
    return json.dumps(self.to_dict())