Заполнение одного выпадающего списка из двух таблиц в django python sqlite

views.py

@login_required(login_url='login')
def create_itementry(request):
forms = ItemEntryForm()
if request.method == 'POST':
    forms = ItemEntryForm(request.POST)
    if forms.is_valid():
        name = forms.cleaned_data['name']
        code = forms.cleaned_data['code']
        make = forms.cleaned_data['make']
        location = forms.cleaned_data['location']
        sublocation = forms.cleaned_data['sublocation']
        quantity = forms.cleaned_data['quantity']
        ItemEntry.objects.create(
            name=name,
            code=code,
            make=make,
            location=location,
            sublocation=sublocation,
            quantity=quantity,
        )
        return redirect('itementry-list')
context = {
    'form': forms
}
return render(request, 'store/addItemEntry.html', context)

def load_items(request):
itemcode_id = request.GET.get('itemcode')
items = Item.objects.filter(itemcode_id=itemcode_id).order_by('name')
return render(request, 'store/item_dropdown_list_options.html', {'items': items})



class ItemEntryListView(ListView):
model = ItemEntry
template_name = 'store/itementry_list.html'

def get_context_data(self, **kwargs):
    context = super().get_context_data(**kwargs)
    context['itementry'] = ItemEntry.objects.all().order_by('-id')
    return context

Я хочу заполнить две колонки в одном выпадающем списке. для выбора пункта & itemcode из одного выпадающего списка.

Я новичок в Django, пожалуйста, предоставьте мне любой метод, чтобы сделать это.

Thanx in Advance.

Вернуться на верх