init
This commit is contained in:
26
app/upload/forms.py
Normal file
26
app/upload/forms.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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
|
||||
Reference in New Issue
Block a user