[Answered ]-Function in Django Model class not taking self argument?

2👍

You can only able to call the method if you have an instance of that model class like

< graph_column_format instance >.get_query()

But There’s no way to use limit_choices_to in that way, but you can add the filter in modelForm constructor like,

Assuming you have query_id field on graph_column_format model

class graph_column_format_form(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(MyOrderForm, self).__init__(*args, **kwargs)
        if self.instance:
            self.fields['query_id'].queryset = graph_column_format.objects.filter(query_id=self.instance.graph_id.query_id)
👤Anoop

Leave a comment