I have a function get_non_open_deals() that contains some business logic, that is used both in the forms and in the view.
class CallsForm(ModelForm):
def __init__(self, company, *args, **kwargs):
super(CallsForm, self).__init__(*args, **kwargs)
self.fields['deal_1'].queryset = self.get_non_open_deals(self.instance, company)
I have it right now duplicated both in forms and in the views. I was wondering if there is a way to define it in one place for both to access it?
Without having more of a code sample to work with it’s hard to show, but it sounds like this should be a method on the model. If this needs to work on multiple models, perhaps a mixin or an abstract base class would be appropriate.
At the very least, you could make it a function in your
models.pymodule.