I have two models for two parts of AC, that is IndoorInventory for the indoor unit which shows all indoor unit information, and OutdoorInventory for showing outdoor unit information.
class IndoorInventory(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
product = models.CharField(max_length=50)
indoor_brand = models.CharField(max_length=100, null=True, blank=True)
indoor_model_no = models.CharField(max_length=100, null=True, blank=True)
indoor_sr_no = models.CharField(max_length=100, null=True, blank=True)
outdoor_model_no = models.CharField(max_length=100, null=True, blank=True)
class OutdoorInventory(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
product = models.CharField(max_length=50)
outdoor_brand = models.CharField(max_length=100, null=True, blank=True)
outdoor_model_no= models.CharField(max_length=100, null=True, blank=True)
outdoor_sr_no = models.CharField(max_length=100, null=True, blank=True)
indoor_model_no= models.CharField(max_length=100, null=True, blank=True)
I am passing a queryset of IndoorInventory to my Django template and fetching all the data there. Below is my VIEW
def clientInventory(request):
context = {}
client_id = request.GET.get('client_id')
id_inven = IndoorInventory.objects.filter(client=client_id)
od_inven = OutdoorInventory.objects.filter(client=client_id)
context['id_inven'] = id_inven
return render(request, 'client-inventory.html', context)
My Template Below
<table id="client-invent-admin" class="table table-striped table-bordered display nowrap">
<thead>
<tr>
<th class="filterhead">ID</th>
<th class="filterhead">Brand</th>
<th class="filterhead">Product/Type</th>
<th class="filterhead">ID Model No</th>
<th class="filterhead">ID SR No</th>
<th class="filterhead">OD Model No</th>
<th class="filterhead">Actions</th>
</tr>
<tr>
<th>ID</th>
<th>Brand</th>
<th>Product/Type</th>
<th>ID Model No</th>
<th>ID SR No</th>
<th>OD Model No</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for invent in id_inven %}
{% if invent.indoor_model_no == '' %}
<tr class="bg-danger">
<td>{{ invent.id }}</td>
<td>{{ invent.indoor_brand }}</td>
<td>{{ invent.product }}</td>
<td>{{ invent.indoor_model_no }}</td>
<td>{{ invent.indoor_sr_no }}</td>
<td>{{ invent.outdoor_model_no }}</td>
<td>
<div class="dropdown icon-dropdown">
<a class="btn-icon dropdown-toggle" data-toggle="dropdown" href="#">
<i class="zmdi zmdi-more"></i>
</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#"><i class="feather icon-eye"></i> View</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#"><i class="feather icon-edit"></i> Edit</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item"
href="/delClient-invent/?invent_id={{invent.id}}&client_id={{client_id}}">
<i class="feather icon-trash"></i> Delete
</a>
</div>
</div>
</td>
</tr>
{% else %}
<tr>
<td>{{ invent.id }}</td>
<td>{{ invent.indoor_brand }}</td>
<td>{{ invent.product }}</td>
<td>{{ invent.indoor_model_no }}</td>
<td>{{ invent.indoor_sr_no }}</td>
<td>{{ invent.outdoor_model_no }}</td>
<td>
<div class="dropdown icon-dropdown">
<a class="btn-icon dropdown-toggle" data-toggle="dropdown" href="#">
<i class="zmdi zmdi-more"></i>
</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#"><i class="feather icon-eye"></i> View</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#"><i class="feather icon-edit"></i> Edit</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item"
href="/delClient-invent/?invent_id={{invent.id}}&client_id={{client_id}}">
<i class="feather icon-trash"></i> Delete
</a>
</div>
</div>
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Brand</th>
<th>Product/Type</th>
<th>ID Model No</th>
<th>ID SR No</th>
<th>OD Model No</th>
<th>Actions</th>
</tr>
</tfoot>
</table>
Now I want to get the outdoor_sr_no from OutdoorInventory models and pass it to the IndoorInventory Queryset so that the outdoor_sr_no value also get fetched on the table next to (OD model no) column in the table