models.pyジャンゴ 'ModelFormOptions' オブジェクトがない属性 'virtual_fields'
class Products(models.Model):
company = models.ForeignKey(Companys)
name = models.CharField(unique = True, max_length = 50)
description = models.CharField(unique = True, max_length = 500)
price = models.PositiveIntegerField()
in_stock = models.BooleanField(default = True)
crated = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
forms.py
class ProductForm(forms.ModelForm):
class Meta:
model = Products
fields = '__all__'
name = forms.CharField()
description = forms.CharField(widget = forms.Textarea,)
company = forms.ModelChoiceField(queryset = Companys.objects.all(), label = 'Company')
in_stock = forms.BooleanField(initial = True)
price = forms.IntegerField()
views.py
class ProductCreate(CreateView, ProductEditMixin):
model = ProductForm
template_name = 'store/product_add.html'
fields = '__all__'
def post(self, request, *args, **kwargs):
self.success_url = reverse('get_context_data', kwargs = {'pk' : Companys.objects.first().id})
return super(ProductCreate, self).post(request, *args, **kwargs)
を持っている私を助けてください。フォームコードの作業なし。しかしフォームで私はAttributeErrorを持っています: 'ModelFormOptions'オブジェクトには属性 'virtual_fields'というエラーはありません
ビューポスト方法を表示できますか?あなたが投稿要求を処理するために使用するメソッド – Lemayzeur
私はそれを追加しますが、私は投稿とget_context_dataのコメントの後にこのエラーがあります – Hman