这是图像。如何从这些选项中删除这些(-----------)行。我正在使用django筛选器
我创建的模型
class Notes(models.Model):
subjects = models.CharField(max_length=100, default=None)
faculty = models.ForeignKey(Faculty, on_delete=models.SET_NULL, null=True)
program = models.ForeignKey(Program, on_delete=models.SET_NULL, null=True)
term = models.CharField(max_length=30, choices=SEMESTER_CHOICES, default=None)
download = models.URLField(max_length=200, blank=True)
def __str__(self):
return self.subjects
class NotesFilter(django_filters.FilterSet):
subjects = CharFilter(field_name='subjects', lookup_expr="icontains", label='Subject', widget=TextInput(attrs={'placeholder':'Enter Subject'}))
term = django_filters.ChoiceFilter(choices=SEMESTER_CHOICES, required=False, label='Semester', empty_label=None,widget=Select(attrs={'placeholder':'Enter Subject'}))
class Meta:
model = Notes
fields = ['subjects', 'faculty', 'program','term']
这些选择选项称为空标签
使用django筛选器,您可以在settings.py中设置^{} ,将所有选项筛选器的默认空标签从
' -'
更改为不同的字符串(例如,空字符串''
,或'Please select an option...'
),或设置为None
,以禁用它您还可以在单个^{} 或^{} 上设置
empty_label
参数。您已经对term
字段执行了此操作如果要在每个字段的基础上自定义
ForeignKey
字段,则需要手动定义ForeignKey
字段,就像对其他字段所做的那样(而不需要执行更复杂的操作,如扩展__init__()
方法),例如:相关问题 更多 >
编程相关推荐