Django如何删除模板中的ForeignKey



我想删除表单和模板中的ForeignKey,它会自动生成并在此处输入代码

模型和表格在那里:

from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm
class PostProduit(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
titre = models.CharField(max_length=255)
categorie = models.CharField(max_length=255)
description = models.TextField(max_length=255)
prix_en_FCFA = models.CharField(max_length=255)
Whatsapp = models.BooleanField(max_length=255)
photo_1 = models.ImageField(upload_to="image/")
photo_1 = models.ImageField(upload_to="image/", null=True, blank=True)
photo_1 = models.ImageField(upload_to="image/", null=True, blank=True)
photo_1 = models.ImageField(upload_to="image/", null=True, blank=True)
date = models.DateTimeField(auto_now=True)
def __str__(self):
return f"{self.user} ===> {self.titre}"
class PostProduitForm(ModelForm):
class Meta:
model = PostProduit
fields = '__all__'

只需在fields变量中添加要添加到表单中的字段,如下所示:

fields = ['titre', 'categorie', 'description', ...]

您可以随时参考Django官方文档了解更多信息。

最新更新