how to load the sale price based on the selecter with django

hi I am a beginner on django and I would like to display the sale price depending on the product selected, see my source codes below. I’m stuck and I can’t unblock, please I need your help.
Thanks for your help

the sales model:

class Sale(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    product = models.ForeignKey('Product', on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)
    sale_price = models.PositiveIntegerField(default=0)
    montant_total = models.CharField(max_length=15, default=0)

    def __str__(self):
        return self.montant_total

the views :

def addSale(request=None):
    current_sale = Sale()
    list_user = User.objects.all().order_by('-username')
    list_product = Product.objects.all().order_by('-name')

    if request.POST:
        if request.POST.get('user') != "":
            current_sale.user = User.objects.get(id=request.POST.get('user'))
        if request.POST.get('product') != "":
            current_sale.product = Product.objects.get(id=request.POST.get('product'))
        if request.POST.get('quantity') != "":
            current_sale.quantity = request.POST.get('quantity')
        if request.POST.get('sale_price') != "":
            current_sale.sale_price = request.GET.get('price')
        if request.POST.get('montant_total') != "":
            current_sale.montant_total = request.POST.get('montant_total')
        current_sale.save()
        return redirect('products-list')
    
    context = {'sale': current_sale, 'list_user': list_user, 'list_product': list_product}
    return render(request, 'daara/add_sale.html', context)

the add_sale.html template:

<div class="card-body">
                       <form method="POST">
                            {% csrf_token %}

                                 <div class="form-group col-md-6">
                                    <label for="utilisateur">Utilisateur</label>
                                    <select
                                        class="form-control" name="user">
                                        <option value="1" selected="selected">Selectionez un utilisateur</option>
                                        {% for user in list_user %}
                                        {% if user.id == sale.user.id %}
                                        <option value="{{sale.user.id}}"  selected="selected">{{sale.user.username}}</option>
                                        {% else %}
                                        <option value="{{user.id}}">{{user.username}}</option>
                                        {% endif %}
                                        {% endfor %}
                                    </select>
                                </div>
                           
                                <div class="form-group col-md-6">
                                    <label for="produit">Produit</label>
                                    <select
                                        class="form-control" name="product" id="product">
                                        <option value="0" selected="selected">Selectionez un produit</option>
                                        {% for product in list_product %}
                                        {% if product.id == sale.product.id %}
                                        <option value="{{sale.product.id}}"  selected="selected">{{sale.product.name}}</option>
                                        {% else %}
                                        <option value="{{product.id}}">{{product.name}}</option>
                                        {% endif %}
                                        {% endfor %}
                                    </select>
                                </div>
                           
                                <div class="form-group col-md-6">
                                    <label for="quantity">Quantity</label>

                                    <input type="number"
                                        class="form-control" id="qte" name="quantity" value="{{sale.quantity}}">
                                </div>
                           
                                <div class="form-group col-md-6">
                                    <label for="sale_price">Price</label><input type="number" step="0.01"
                                          class="form-control" id="product_price" name="sale_price" value="{{product.price}}">
                                </div>
                           
                                 <div class="form-group col-md-6" id="#montant">
                                    <label for="montant">Montant Total</label> <input  type="number" step="0.01"
                                        class="form-control" id="montant" name="montant_total" value="{{sale.montant_total}}">
                                </div>



                            <div class="text-end">
                                 <a class="btn btn-secondary" href="{% url 'products-list' %}" type="button">Close</a>
                                <button class="btn btn-success" type="submit"  value="save">Save</button>

                           </div>
                       </form>
                       <p>{{product_id}}aaa</p>

                    </div>

the url:

path('ad-sale', views.addSale, name="ad-sale")

I’m stuck and I can’t unblock, please I need your help

New contributor

Power Comparison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật