Registering Django objects with child objects

I have two tables named product and variant. I am building an offer creation module. While creating the offer, I want to pull the products from the product and variant table and save them to the offer product table, but I am having problems with the checkboxes.

Can you help me @KenWhitesell

from django.db import models
from firma.models import company

class variant(models.Model):
    name = models.CharField('Varyant Adı',max_length=200)
    price = models.IntegerField('Varyant Fiyat')    
    stok = models.IntegerField('Varyant Stok')    
    company = models.ForeignKey(company,on_delete=models.CASCADE)
    image = models.FileField(upload_to="variant",default="")
    def __str__(self):
        return f"{}"
class product(models.Model):
    name = models.CharField('Ürün Adı',max_length=200)
    price = models.IntegerField('Ürün Fiyat')
    stok = models.IntegerField('Ürün Stok')
    variant = models.ManyToManyField(variant,blank=True)
    company = models.ForeignKey(company,on_delete=models.CASCADE)
    image = models.FileField(upload_to="product",default="")
    def __str__(self):
        return f"{}"

class offerProductInfo(models.Model):
    offerProductName = models.CharField('Ürün Adı',max_length=200)
    offerProductPrice = models.IntegerField('Ürün Fiyat')
    offerProductStok = models.IntegerField('Ürün Stok')
    offerProductVariant = models.ManyToManyField(offerVariantInfo,blank=True)
    offerProductCompany = models.ForeignKey(company,on_delete=models.CASCADE)
    offerProductImage = models.ImageField(upload_to="product")
    def __str__(self):
        return f"{self.offerProductName}"

def teklifsave(request):
    if not request.user.is_authenticated:
        return redirect('login')
    if request.method == 'POST':
        offerVariantId = request.POST.getlist('offerVariantId')
        offerProduct = request.POST.getlist("offerProducts")
        count = -1
        for fproduct in offerProduct:
            count += 1
            h = variant.objects.get(id=offerVariantId[count])
            c = h.product_set.all()
            s = offerVariantInfo(
                offerVariantName =,
                offerVariantPrice = h.price,
                offerVariantStok = h.stok,
                offerVariantCompany =
            z = product.objects.get(id=fproduct)
            c = offerProductInfo(
                offerProductName =,
                offerProductPrice = z.price,
                offerProductStok = z.stok,
                offerProductCompany =,
                offerProductImage = z.image
        return redirect('offer')
    return redirect('offer')

template (I have it in my elements and it does the post processing, I didn’t add it because there is too much code in the top and bottom tar)

<div id="kt_modal_add_customer_billing_info" class="collapse show">				
															{% for product in products %}
																<!--begin::Input group-->
																<div id="offerProductsVariants">

																<div class="fv-row mb-7">
																		<label class="btn btn-outline btn-outline-dashed btn-outline-default p-7 d-flex align-items-center mb-5" for="kt_radio_buttons_2_option_1">
																			<!--begin::Svg Icon | path: icons/duotune/coding/cod001.svg-->
																			<span class="svg-icon svg-icon-4x me-4">
																				<img style="width:150px;" src="{{ product.image.url }}" />
																			<!--end::Svg Icon-->
																			<span class="d-block fw-bold text-start">
																				<span class="text-dark fw-bolder d-block fs-3">{{ }}</span>
																				<span class="text-muted fw-bold fs-6">
																					₺{{ product.price }}
																			<div class="form-check form-check-custom form-check-solid" id="product-check" style="position:absolute; right:60;">
																				<div id="{{ offerForm.offerProduct.auto_id }}">
																						<label for='id_offerProduct'>
																							<input class="form-check-input offerProductsCheckbox" type="checkbox" name='offerProducts' value="{{ }}" id="id_offerProduct_{{ }}"/>

																		<div class="accordion" id="kt_accordion_1">
																			<div class="accordion-item">
																				<h2 class="accordion-header" id="kt_accordion_1_header_{{ }}">
																					<button class="accordion-button fs-4 fw-bold collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#kt_accordion_1_body_{{ }}" aria-expanded="true" aria-controls="kt_accordion_1_body_{{ }}">
																						{{ }}'in Alt Ürünleri
																				<div id="kt_accordion_1_body_{{ }}" class="accordion-collapse collapse" aria-labelledby="kt_accordion_1_header_{{ }}" data-bs-parent="#kt_accordion_1">
																					<div class="accordion-body">
																						{% for variant in product.variant.all %}
																							<div class="variant">
																								<b>{{ }} </b>- ₺<b>{{ variant.price }}</b><br />
																									<div class="form-check form-check-custom form-check-solid" id="variant-check" style="position:absolute; right:60;">
																									<div id="{{ offerForm2.offerVariant.auto_id }}">
																											<label for='id_offerVariant'>
																												<input class="form-check-input offerVariantsCheckbox" type="checkbox" name='offerVariantId' value="{{ }},{{ }}" id="id_offerVariant_{{ }}"/>
																						{% endfor %}

																<!--end::Input group-->
															{% endfor %}

I’m sorry, I’m not sure I’m following what you’re asking for here.

You’re showing references to tables that you’re not showing the models (e.g. offerProductInfo has a field named offerProductVariant which is a ManyToManyField with an offerVariantInfo model - which isn’t shown here anywhere.)

It’s also difficult to read your code since it doesn’t follow any of the standard Python / Django code conventions.

I’m also extremely confused by you having a ManyToMany relationship between product and variant. On the surface, this doesn’t make sense for this type of application. (If I’m interpreting your intent correctly, I could see variant having a ForeignKey to product, but I’m not sure that’s the real need for your application.)

My first reaction to all this is that you should at a minimum ensure that your models are a proper relational model for your business requirements.

Then I would suggest adopting the Django coding conventions, but for the moment that’s not critical.

Finally, can you be more specific about:

What exactly is the problem you are encountering? (What is happening that you’re not expecting to happen, or what is not happening that you are expecting to see?)