您好,我正在尝试为我的网站上的用户创建一个表单,以便能够添加产品,我使用 ModelForm 制作了该表单,并且我已设法在我的模板中呈现它,但它没有按要求运行。提交表单时,我不断收到验证错误,表明图像尚未提交,但我确实添加了它们,有什么想法吗模型from django.db import modelsclass Product(models.Model): name = models.CharField(max_length=120) price = models.FloatField() image_182x182 = models.ImageField(upload_to='pdt_imgs/') image_1200x1200 = models.ImageField(upload_to='pdt_imgs/alt_imgs/') image_600x600 = models.ImageField(upload_to='pdt_imgs/alt_imgs/') image_600x600_2 = models.ImageField(upload_to='pdt_imgs/alt_imgs/') image_300x300 = models.ImageField(upload_to='pdt_imgs/alt_imgs/') img_array = [image_1200x1200, image_600x600, image_600x600_2] sku = models.IntegerField() available = models.BooleanField(default=True) discount = models.IntegerField(default = 0) category = models.ForeignKey(SubCategory, on_delete=models.CASCADE) seller = models.ForeignKey(Seller, on_delete=models.CASCADE) def __str__(self): return self.name def get_absolute_url(self): return reverse('pdt_detail', args=[str(self.id)]) def get_add_to_cart_url(self): return reverse('add-to-cart', args= [str(self.id)] ) 形式from .models import Productfrom django.forms import ModelFormclass ProductForm(ModelForm): class Meta: model = Product fields = [ 'name', 'price', 'image_182x182', 'image_1200x1200', 'image_600x600', 'image_600x600_2', 'image_300x300', 'sku', 'available', 'discount', 'category', 'seller' ]意见from django.utils.decorators import method_decoratorfrom .decorators import seller_requiredfrom django.views.generic import CreateViewfrom store.models import Productfrom store.forms import ProductFormfrom django.contrib import messages
1 回答
catspeake
TA贡献1111条经验 获得超0个赞
<form class="ps-form--account-setting" method="post" enctype="multipart/form-data">
添加回答
举报
0/150
提交
取消