我正在使用此通用视图,我想仅针对某些类型过滤campaign_type。 我试图使用queryset = CampaignType.objects.filter(type ='social')但它不起作用。任何线索? 请注意,过滤器与CampaignType有很多关系,我的模型是Campaign。
class CCtypeUpdate(generic.UpdateView):
model = Campaign
fields = ['campaign_type']
template_name = 'campaign/campaign.html'
success_url = '../../'
答案 0 :(得分:2)
试试这个
class CCtypeUpdate(generic.UpdateView):
model = Campaign
fields = ['campaign_type']
......
#rest of your code
def get_form(self, form_class=None):
form = super(CCtypeUpdate, self).get_form(form_class)
form.fields["campaign_type"].queryset = CampaignType.objects.filter(type='social')
return form