Am developing a web app where i want to view per client details
-- view.py
class DirectorListView(ListView):
model = Director
paginate_by = 10
def get_queryset(self):
query = self.request.GET.get('q')
if query:
search = Director.objects.filter(first_name__icontains=query)
return search
else:
return Director.objects.order_by('first_name')
model.py
class Client(models.Model):
name = models.CharField(max_length=200)
registration_number = models.CharField(max_length=200)
vat_number = models.CharField(max_length=200,null=True,blank=True)
ownership = models.CharField(max_length=200,choices=choices,default='Private')
year = models.CharField(max_length=200)
number_year = models.IntegerField(null=True,blank=True)
country = models.CharField(max_length=200)
sector = models.ForeignKey(Sector,related_name='client',on_delete=models.SET_NULL,null=True)
location = models.CharField(max_length=200)
postal_address = models.CharField(max_length=200)
email = models.EmailField()
website = models.CharField(max_length=200,null=True)
mobile_number = models.CharField(max_length=200)
contact_person = models.CharField(max_length=200)
contact_number = models.CharField(max_length=200)
date_time = models.DateField(default=timezone.now)
registration_certificate = models.FileField(upload_to='certificate/%Y/%m/%d/',null=True,blank=True)
vat_certificate = models.FileField(upload_to='vat/%Y/%m/%d/',null=True,blank=True)
def __str__(self):
return self.name
class Director(models.Model):
client = models.ForeignKey(Client, related_name='director',on_delete=models.SET_NULL,null=True)
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
phone_number = models.CharField(max_length=200)
email = models.EmailField()
id_number = models.CharField(max_length=200,null=True,blank=True)
postal_address = models.CharField(max_length=200,null=True,blank=True)
position = models.CharField(max_length=200,null=True,blank=True)
kra = models.FileField(upload_to='kra/%Y/%m/%d/',null=True,blank=True)
national_id = models.FileField(upload_to='ids/%Y/%m/%d/',null=True,blank=True)
def __str__(self):
return "{} {}".format(self.first_name, self.last_name)
client_detail.html
{% extends 'base.html' %}
{% block content %}
{% load humanize %}
<div class="row">
<div class="col-sm-4">
<table class="table table-bordered" width="100%" cellspacing="0">
<tr> <th style="color: blue;">Name</th> <td style="color: black;">{{ client.name }} </td> </tr>
<tr> <th style="color: blue;">Year of operation</th> <td style="color: black;">{{client.number_year}}</td> </tr>
</table>
</div>
<div class="col-sm-4">
<table class="table table-bordered" width="100%" cellspacing="0">
<tr> <th style="color: blue;">Company No</th> <td style="color: black;">{{client.registration_number}}</td> </tr>
<tr> <th style="color: blue;">Email</th> <td style="color: black;">{{client.email}}</td> </tr>
</table>
</div>
<div class="col-sm-4">
<table class="table table-bordered" width="100%" cellspacing="0">
<tr> <th style="color: blue;">Documents</th> <td> <a href="{{client.vat_certificate.url}}" > VAT </a> <a href="{{client.registration_certificate.url}}" > Registration Certificate </a></td> </tr>
<tr> <th style="color: blue;">Country</th> <td style="color: black;">{{client.country}}</td> </tr>
</table>
</div>
</div>
<div class="row" >
<div class="col-sm-9">
<div class="card-body">
<div class="row">
<div class="col-sm-2">
<a class="btn btn-default buttonsAlign" href="{% url 'assest_list' %}"><span style="color: black;font-weight:bold;">ASSESTS</span></a>
</div>
<div class="col-sm-2">
<a class="btn btn-default buttonsAlign" href="{% url 'bankstatement_list' %}"><span style="color: black;font-weight:bold;">BANK STATEMENT</span></a>
</div>
<div class="col-sm-2">
<a class="btn btn-default buttonsAlign" href="{% url 'offtaker_list' %}"><span style="color: black;font-weight:bold;"> OFF-TAKERS </span></a>
</div>
<div class="col-sm-2">
<a class="btn btn-default buttonsAlign" href="{% url 'director_list' %}"><span style="color: black;font-weight:bold;"> DIRECTORS </span></a>
</div>
</div>
</div>
<div class="card shadow mb-4">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th >Turnover</th>
<th>Expenses </th>
<th>Income</th>
<th>Currency</th>
<th>Year</th>
<th>Employees</th>
</tr>
</thead>
{% for financial in client.financial.all %}
<tbody>
<tr>
<td>{{ financial.turnover|intcomma}}</td>
<td>{{financial.expenses|intcomma}}</td>
<td>{{ financial.income|intcomma }}</td>
<td>{{financial.currency}}</td>
<td>{{financial.year}}</td>
<td>{{financial.number_employees}}</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card shadow mb-4">
<div class="card-body">
<div class="panel-default">
<a class="btn btn-info buttonsAlign" href="{% url 'add_client_financial' pk=client.pk %}"><span>Add Financials </span></a>
<a class="btn btn-info buttonsAlign" href="{% url 'add_client_assest' pk=client.pk %}"><span>Add Assets</span></a>
<a class="btn btn-info buttonsAlign" href="{% url 'add_client_directors' pk=client.pk %}"><span>Add Directors </span></a>
<a class="btn btn-info buttonsAlign" href="{% url 'add_client_bankstatement' pk=client.pk %}"><span>Add Bank Statements</span></a>
<a class="btn btn-info buttonsAlign" href="{% url 'add_client_offtakerprifile' pk=client.pk %}"><span>Add Off-Takers</span></a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
When i click on DIRECTORS it displays all directors of all the clients i have, how can filter based on client pk?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2d9f3d28-71f6-4e50-9cf7-8b9399f40262%40googlegroups.com.
No comments:
Post a Comment