Ошибка: ValueError at /music/upload/
The Files could not be created because the data didn't validate.
Не понимаю почему
Модель:
class Files(models.Model):
user = models.ForeignKey(User)
text = models.CharField(max_length=100)
artist = models.CharField(max_length=50)
our_file = models.FileField(upload_to='profile_image')
image = models.ImageField(upload_to='profile_image', blank=True, default='new.jpg')
data_time = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.text
Форма:
class UploadForm(forms.ModelForm):
text = forms.CharField(widget=forms.TextInput(
attrs={
'class': 'form-control',
'placeholder': 'Введите название песни...'
}
))
artist = forms.CharField(widget=forms.TextInput(
attrs={
'class': 'form-control',
'placeholder': 'Введите имя исполнителя...'
}
))
class Meta:
model = Files
fields = (
'text',
'artist',
'our_file',
'image',
)
В шаблоне:
<form action="" method="post">
{% csrf_token %}
{{form.text}}
<br>
{{form.artist}}
<hr>
{{form.our_file}}
<br>
{{form.image}}
<button type="submit" class="btn btn-success btn-lg">Подтвердить</button>
</form>
В view:
class Upload(TemplateView):
template_name = 'home/upload.html'
def get(self, request):
form = UploadForm()
args = {
'form': form
}
return render(request, self.template_name, args)
def post(self, request):
form = UploadForm(request.POST)
if form.is_valid():
new = form.save(commit=False)
new.user = request.user
new.save()
return redirect('music:home')
return redirect('music:home')