

def save(self):
    if (not self.data['choice']):
        return
    t = self.report
    model = loads(t.model)
    classobj = model.get_class_object()
    xfield = classobj._meta.get_field_by_name(self.field_name)[0]
    field = model.get_field(self.field_name)
    if (not field.filters):
        field.filters = []
    c = self.data['choice']
    type = xfield.get_internal_type()
    if (type == 'ManyToManyField'):
        c = xfield.related.parent_model.objects.filter(pk=c)[0]
    if (type == 'ForeignKey'):
        c = xfield.related.parent_model.objects.filter(pk=c)[0]
    display_choice = model
    if hasattr(self.fields['choice'], 'choices'):
        for (choice, dc) in self.fields['choice'].choices:
            if (unicode(c) == unicode(choice)):
                display_choice = dc
                break
    for (choice, dc) in self.fields['operand'].choices:
        if (unicode(self.data['operand']) == unicode(choice)):
            display_operand = dc
            break
    display = ('%s %s %s' % (field.get_human_name(), display_operand, unicode(display_choice)))
    field.filters.append({
        'choice': c,
        'operand': self.data['operand'],
        'display': display,
    })
    t.model = dumps(model)
    t.save()

dataset/ETHPy150Open treeio/treeio/treeio/reports/forms.py FilterForm.save/VarMisuse@173/211 `c`->`model`