0

私はモデルのために4つのファイルフィールドを持つ必要があります。そのために、私はDjangoインラインモデルを使用しています。私はまた、ユーザーがフォームを記入できるように、すべてのthodeフィールドを持つモデルを作成する必要があります。クラスベースのビュー - CreateViewを使用しています。しかし、私は私のモデルフォームでファイルフィールドを取得する方法を知らない。Djangoインラインモデルフロントエンド

Models.py

class Product(models.Model) 

name= models.Charfield(maxlength=50) 
city= models.Charfield(maxlength=50) 
state=model.Charfield(maxlength=50) 
year=models.Integerfield(blank=True, null=True) 

class ProductAttachment(models.Model) 

attachment = models.ForeignKey(Product, related_name='attachment') 
appendix_a= models.Filefield(verbose_name='Appendix A') 
appendix_b= models.Filedield(verbose_name='Appendix B') 
Other = models.Filefield() 

Admin.py

class ProductInline(admin.StackedInline) 
    model=ProductAttachment 


class ProductAdmin(admin.modelAdmin) 
    inlines= [ProductInline,] 
    model=Product 
admin.site.register(Product, ProductAdmin) 

forms.py

class ProductForm(models.form): 
    class Meta: 
     model=Product 
     fields='__all__' 

Views.py

class ProductCreateView(CreateView): 
    model=Product 
    form_class = ProductForm 

しかし、私はフォームのすべてのファイルフィールドを取得する方法がわかりません。どんな助けも高く評価されます。ありがとうございました

答えて

0

あなたのコードを見ると、ProductFormとProductCreateViewのモデルはFileFiledを含まないProductです。 ProductAttachmentのフォーム/ビューも作成する必要があります。

関連する問題