How to get select options from django models?

I am not able to render product in my order model on my html page. I am trying to find out the problem here. but as i select form.product.model_name it should get me the model names, but its blank in options. Below I am attaching the code to check it out,

in my

from cgi import print_form
from email.policy import default
from enum import unique
from django.db import models

# Create your models here.
class ProductModel(models.Model):
    product_id = models.CharField(max_length=100,unique=True, default = '0')
    product_name = models.CharField(max_length=100, default=" ")
    model_name = models.CharField(max_length=100, default=" ")

    def __str__(self):
        return str(self.product_id)

productchoice = (ProductModel.objects)
class OrderModel(models.Model):
    order_id = models.AutoField(unique=True, primary_key=True)
    Customer_name = models.CharField(max_length=100)
    Father_name = models.CharField(max_length=100)
    Village = models.CharField(max_length=100)
    Tehsil = models.CharField(max_length=100)
    District = models.CharField(max_length=100)
    State = models.CharField(max_length=100)
    product = models.ForeignKey(ProductModel, on_delete = models.CASCADE, default= 0)

    def __str__(self):
        return str(self.order_id)

in my

from email import message_from_binary_file
from django.shortcuts import render
from .models import OrderModel, ProductModel
from .forms import OrderForm, ProductForm
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib import messages
from django.contrib.messages import get_messages

# Create your views here.

def home(request):
    order_form = OrderForm
    if request.method == 'POST':
        order_form = OrderForm(request.POST)

        if order_form.is_valid():
            messages.success(request, ('Your data was successfully added!'))
            return HttpResponseRedirect('/')
            messages.error(request, order_form.errors)

    orders = OrderModel.objects.all()
    context = {'order':orders, 'form':order_form}
    return render(request,'Orders/addorder.html',context)

def product(request):
    product_form = ProductForm

    if request.method == 'POST':
        product_form = ProductForm(request.POST)

        if product_form.is_valid():
            messages.success(request,"Your Products is successfully saved!")
            return HttpResponseRedirect('/')

    products = ProductModel.objects.all()
    context = {'product':products, 'form':product_form}
    return render(request,'Orders/addproduct.html',context)

my html page

{% extends 'OMS/index.html' %}
{% load static %}

{% block title %}
{% endblock %}

{% block main %}

    <link rel="stylesheet" href="{% static 'addorder.css' %}">
    <div class="container mp-3">
        <h1>Create your Order</h1>
         <form action="" method="POST">
            {% csrf_token %}
                <label for="Customer Name" class="form-label">Customer Name: </label>
                {{ form.Customer_name }}
                <label for="Father Name" class="form-label">Father Name: </label>
                {{ form.Father_name }}
                <label for="Village" class="form-label">Village: </label>
                {{ form.Village }}
                <label for="Tehsil" class="form-label">Tehsil: </label>
                {{ form.Tehsil }}
                <label for="District" class="form-label">District: </label>
                {{ form.District }}
                <label for="State" class="form-label">State: </label>
                {{ form.State }}
                <select name="product" id="productselection">
                        {% for form in form %}
                            <option value="{{ form.product.product_id }}">{{ form.product.model_name }}</option>
                        {% endfor %}

            <button type="submit">Submit</button>
            {% if messages %}
                <ul class="messages">
                {% for message in messages %}
                    <li {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
                {% endfor %}
            {% endif %}
{% endblock %}


from django import forms
from .models import OrderModel, ProductModel, productchoice

class OrderForm(forms.ModelForm):
    Customer_name = forms.CharField(widget=forms.TextInput(attrs={

    class Meta:
        model = OrderModel
        fields = "__all__"

class ProductForm(forms.ModelForm):

    class Meta:
        model = ProductModel
        fields = "__all__"

Back to Top