問題

考慮:

 >>>jr.operators.values_list('id')
[(1,), (2,), (3,)]
 

如何進一步簡化:

 ['1', '2', '3']
 

目的:

 class ActivityForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(ActivityForm, self).__init__(*args, **kwargs)
        if self.initial['job_record']:
            jr = JobRecord.objects.get(pk=self.initial['job_record'])

            # Operators
            self.fields['operators'].queryset = jr.operators

            # select all operators by default
            self.initial['operators'] = jr.operators.values_list('id') # refined as above.
 

  最佳答案

  相同標籤的其他問題

pythondjango