Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
996 B
2
Indexable
Never
forms.py

class SelectPortfolioForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(SelectPortfolioForm, self).__init__(*args, **kwargs)
        self.fields['portfolio_names_trading'].required = True

    portfolio_names_trading = forms.ModelMultipleChoiceField(
        queryset=CoreAppPortfolios.objects.values_list('portfolio_name', flat=True).filter(
            portfolio_type__in=['COUNTERPARTY', ]))

    portfolio_names_customer = forms.ModelMultipleChoiceField(
        queryset=CoreAppPortfolios.objects.exclude(portfolio_name__in=['TEST_GAS', 'GAS_TEST_2'])
            .values_list('portfolio_name', flat=True).filter(portfolio_type__in=['CUSTOMER', 'HEDGER']))

***********************************************************************************

site.html

<select class="selectpicker" multiple data-live-search="true" name="portfolio_names_trading" required>
    {% for el in portfolio_form.portfolio_names_trading %}
        {{ el }}
    {% endfor %}
</select>