-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
39 lines (30 loc) · 1.24 KB
/
models.py
File metadata and controls
39 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import reprlib
from django.contrib.auth import get_user_model
from django.db import models
from django_stubs_ext.db.models import TypedModelMeta
User = get_user_model()
class UserFile(models.Model):
"""
UserFile model
Attributes:
link: Link to the file on the CDN
user: User who uploaded the file
datetime_uploaded: Datetime when the file was uploaded
name: Name of the file
extension: Extension of the file
size: Size of the file in bytes
"""
link = models.URLField(primary_key=True, null=False)
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
datetime_uploaded = models.DateTimeField(auto_now_add=True)
name = models.TextField(blank=False, default="file")
extension = models.TextField(blank=True, default="")
mime_type = models.CharField(max_length=256, default="")
size = models.PositiveBigIntegerField(null=False, blank=True, default=1)
def __str__(self):
filename_with_extension = f"{self.name}.{self.extension}"
return f"UserFile<{reprlib.repr(filename_with_extension)}>"
class Meta(TypedModelMeta):
verbose_name = "Файл"
verbose_name_plural = "Файлы"
ordering = ["datetime_uploaded"]