Last active
October 13, 2017 07:05
-
-
Save ragowthaman/28eb507b70fa3ada5dca9953d16b78d6 to your computer and use it in GitHub Desktop.
Display model data onto a template : URL -> Views(model) -> Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "base_instance.html" %} | |
{% load i18n staticfiles %} | |
{% load templatetag_generic %} | |
{% block meta_title %}{% trans "Consultants" %}{% endblock %} | |
{% block title %} | |
{{ affiliation }} : | |
Consultant(s) List | |
{% endblock %} | |
{% block extra_css %} | |
<link rel="stylesheet" href="/static/css/base_instance.css"> | |
{% endblock %} | |
{% block extra_js %} | |
<script src="/static/js/base_instance.js"></script> | |
{% endblock %} | |
{% block main %} | |
<div class="collapsible-table"> | |
<div class="table-name-button"><span>Consultant(s):</span></div> | |
<div class="table-content"> | |
<p></p> | |
<TABLE> | |
<TR><TH>Sl. No</TH><TH>Name</TH><TH>Associated Farmers</TH><TH>Affiliation</TH><TH>Contact</TH><TH>Taluk, District</TH><TH>Address</TH></TR> | |
{% for consultant in consultants %} | |
<TR> | |
<TD class="center-align">{{ forloop.counter }}</TD> | |
<TD>{{ consultant.firstname }} {{ consultant.lastname }}</TD> | |
<TD class="center-align"><a href="/instance/list/farmers/{{ consultant.id }}/">Farmer(s)</a></TD> | |
<TD class="center-align">{{ consultant.affiliation }}</TD> | |
<TD>{{ consultant.phone }} <br> {{ consultant.phone2 }} <br> {{ consultant.email }}</TD> | |
<TD>{{ consultant.taluk }}, <br> {{ consultant.district }}</TD> | |
<TD>{{ consultant.street }} <br> {{ consultant.pincode }}</TD> | |
</TR> | |
{% endfor %} | |
</TABLE> | |
</div> | |
</div> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url(r'^list/consultants/$', 'instance.views.list_consultants'), | |
url(r'^list/consultants/(?P<consultant_id>.+)/$', 'instance.views.list_consultants'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_consultants(request, consultant_id=None): | |
""" | |
List all the consultants. | |
:param request: | |
:return: List of consultants | |
""" | |
# todo: Later restrict the listing by region | |
kwargs = {} | |
kwargs['affiliation'] = "vidhaikalam" | |
consultants = Consultant.objects.all() | |
if str(request.user) != "vidhaikalam": | |
kwargs['affiliation'] = Consultant.objects.get(admin_username=request.user).business_affiliation.shortname | |
consultants = consultants.filter(business_affiliation__shortname=kwargs['affiliation']) | |
if consultant_id is not None: | |
consultants = consultants.filter(id=consultant_id) | |
kwargs['consultants'] = consultants | |
return render_to_response('instance/list_consultants.html', kwargs, | |
context_instance=RequestContext(request)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment