Files
oximg/app/upload/forms.py
2025-08-31 00:29:53 +02:00

27 lines
554 B
Python

from django import forms
from .models import Upload, Image
class UploadImageForm(forms.ModelForm):
class Meta:
model = Image
fields = ['file']
def save(self, commit=True):
image = super().save(commit=False)
if not image.name:
image.name = image.file.name
if not image.content_type:
from utils import get_mimetype
image.content_type = get_mimetype(image.file)
image.size = image.file.size
if commit:
image.save()
return image