处理脆皮表格时如何删除字段上的"*"符号?



所以在脆皮表单文档(链接在这里:https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html#change-required-fields)中,它声明:

星号有一个asteriskField类集。所以你可以用CSS规则。

models.py

class Post(models.Model, HitCountMixin):
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateField(auto_now_add=True)
image = models.ImageField(default='default_pics/default_post.jpg', upload_to='post_pics')
# a teacher can have many blog posts
author = models.ForeignKey(Teacher, on_delete=models.SET_NULL, null=True)

forms.py

class BlogFrom(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'content', 'image']
widgets = {
'image': forms.FileInput(attrs={"class":"asteriskField"})
}
help_texts = {
'image': 'If you do not set any image, one will be set automatically for you upon creation.'
}

我不知道如何从这里开始。救救我吧!

如文档中所述,如果使用.asteriskField {display: none; },您可以将其添加到css文件中。或者加入<style> .asteriskField {display: none; } </style>到模板的头文件

相关内容

  • 没有找到相关文章

最新更新