У меня есть форма
class OrderItemsImportForm( forms.ModelForm ):
oem = forms.CharField(max_length=128, required=True)
field_order = ['oem', ....]
class Meta:
model = Orderitem
fields = (.....,)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.is_bound:
oem = self.data.get('oem')
else:
oem = kwargs['initial']['oem']
self.fields['part'].queryset = Part.objects.filter(oem=oem)
Но код
oem = self.data.get('oem')
возвращает None, потому что если я печатаю self.data, он содержит что-то вроде:
data = <QueryDict: {'csrfmiddlewaretoken': ['HOCNE7mZmuIXz0RvabrEBFlGQU1qwvThtdj2xtMw8n6tsYGbhq2jNze1JFHSVcIL'], 'ordercomposingitem_set-TOTAL_FORMS': ['2'], 'ordercomposingitem_set-INITIAL_FORMS': ['0'], 'ordercomposingitem_set-MIN_NUM_FORMS': ['0'], 'ordercomposingitem_set-MAX_NUM_FORMS': ['1000'], 'ordercomposingitem_set-0-id': [''], 'ordercomposingitem_set-0-order': [''], 'ordercomposingitem_set-0-oem': ['8844026100'], 'ordercomposingitem_set-0-count': ['100'], 'ordercomposingitem_set-0-price_prefered': ['0'], 'ordercomposingitem_set-0-part': ['88'], 'ordercomposingitem_set-0-user_reference': ['12345'], 'ordercomposingitem_set-0-user_partnumber': ['MY-12345'], 'ordercomposingitem_set-0-user_partbrand': ['My-Supa-Brand'], 'ordercomposingitem_set-0-user_partname': ['My Partname'], 'ordercomposingitem_set-0-user_price': ['100'], 'ordercomposingitem_set-0-user_comment': ['Please make it better!'], 'ordercomposingitem_set-1-id': [''], 'ordercomposingitem_set-1-order': [''], 'ordercomposingitem_set-1-oem': ['31170RNAA02'], 'ordercomposingitem_set-1-count': ['150'], 'ordercomposingitem_set-1-price_prefered': ['0'], 'ordercomposingitem_set-1-part': [''], 'ordercomposingitem_set-1-user_reference': ['789456'], 'ordercomposingitem_set-1-user_partnumber': [''], 'ordercomposingitem_set-1-user_partbrand': ['My-Supa-Brand'], 'ordercomposingitem_set-1-user_partname': [''], 'ordercomposingitem_set-1-user_price': [''], 'ordercomposingitem_set-1-user_comment': ['Hello!'], 'action': ['save']}>
там, где нет чистого поля «oem», только «ordercomposingitem_set-0-oem» и тому подобное.
Как получить доступ к значению поля oem?