我有这个代码
ModelC
在表单验证中,当from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from .models import ModelA
class ModelTypeFilter(SimpleListFilter):
title = 'Model Type'
parameter_name = 'model_type'
def lookups(self, request, model_admin):
model_types = set([m.get_type() for m in model_admin.model.objects.select_subclasses()])
return sorted([(mt, mt) for mt in model_types], key=lambda x: x[1])
def queryset(self, request, queryset):
if self.value():
qs = ModelA.objects.filter(
id__in=[m.id for m in queryset if self.value() in m.get_inherited_types()]).select_subclasses()
return qs
@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
fields = ['name']
ordering = ['name']
list_display = ('name', 'type',)
search_fields = ('name',)
list_filter = [ModelTypeFilter]
def get_queryset(self, request):
qs = super(ModelAAdmin, self).get_queryset(request).select_subclasses()
return qs
def type(self, obj):
return obj.get_type()
失败时,Angular将<div>
<input formControlName="foo" />
</div>
CSS类自动附加到该元素,我想知道它是否可以与其他元素(<input>
这种情况)?