Django-mptt display hierarchy as table - django

I am trying to display a hierarchical table as a normal table.
model.py
class Dimension_value(MPTTModel):
name = models.CharField(max_length = 200, null=True, blank = True, default = '')
parent = TreeForeignKey("self", on_delete=models.CASCADE, null=True, blank=True, related_name="children")
class MPTTMeta:
order_insertion_by = ['name']
def __str__(self):
return self.name
views.py
def show_genres(request):
return render(request, "accounts/dimension_detail.html", {'dimensions': Dimension_value.objects.all()})
dimension_detail.html
<div class="container-fluid">
<div class="card">
<div class="card-body">
<h2>My dimensions</h2>
{% load mptt_tags %}
<ul>
{% recursetree dimensions %}
<li>
{{ node.name }}
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
</div>
</div></div>
Using django-mptt the lists show just fine. However I have no idea how to display this in a normal table.
For example
Europe|The Netherlands|Noord-Holland
Europe|The Netherlands|Zuid-Holland
Europe|Belgium|Vlaanderen
what I currently get
<table>
<thead>
<tr>
<th class="id orderable">ID</th>
<th class="name orderable">Name</th>
<th class="orderable parent">Parent</th>
<th class="asc lft orderable">Lft</th>
<th class="orderable rght">Rght</th>
<th class="asc orderable tree_id">Tree Id</th>
<th class="level orderable">Level</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td class="id">6</td>
<td class="name">Asia</td>
<td class="parent">—</td>
<td class="lft">1</td>
<td class="rght">4</td>
<td class="tree_id">1</td>
<td class="level">0</td>
</tr>
<tr class="odd">
<td class="id">8</td>
<td class="name">Japan</td>
<td class="parent">Asia</td>
<td class="lft">2</td>
<td class="rght">3</td>
<td class="tree_id">1</td>
<td class="level">1</td>
</tr>
<tr class="even">
<td class="id">5</td>
<td class="name">Europe</td>
<td class="parent">—</td>
<td class="lft">1</td>
<td class="rght">8</td>
<td class="tree_id">2</td>
<td class="level">0</td>
</tr>
<tr class="odd">
<td class="id">7</td>
<td class="name">Belgium</td>
<td class="parent">Europe</td>
<td class="lft">2</td>
<td class="rght">7</td>
<td class="tree_id">2</td>
<td class="level">1</td>
</tr>
<tr class="even">
<td class="id">9</td>
<td class="name">Vlaanderen</td>
<td class="parent">Belgium</td>
<td class="lft">3</td>
<td class="rght">4</td>
<td class="tree_id">2</td>
<td class="level">2</td>
</tr>
<tr class="odd">
<td class="id">10</td>
<td class="name">Wallonie</td>
<td class="parent">Belgium</td>
<td class="lft">5</td>
<td class="rght">6</td>
<td class="tree_id">2</td>
<td class="level">2</td>
</tr>
</tbody>
</table>

Related

How to get foreign key detailed values based on id in html template in django

In Models.py
class Interview(models.Model):
Current_Date = models.DateField(auto_now_add=True )
User = models.ForeignKey(User,on_delete=models.CASCADE)
Recuirement = models.ForeignKey(Client_Requirement,on_delete=models.CASCADE)
Candidate = models.ForeignKey(Candidate, on_delete=models.CASCADE)
Interviewer = models.ForeignKey(Interviewer, on_delete=models.CASCADE)
Interview_Mode = models.ForeignKey(Interview_Mode, on_delete=models.CASCADE)
Date = models.DateField()
Time = models.TimeField()
Interview_status = models.ForeignKey(Interview_status, on_delete=models.CASCADE)
Interview_Location = models.CharField(max_length=30)
Comments = models.TextField(max_length=1000)
Update_Date = models.DateTimeField(auto_now=True)
def __str__(self):
return str(self.Interviewer)
in Views.py
def BD(request):
Interview_data = Interview.objects.all()
context={'Interview_data':Interview_data}
return render(request,'Sub/BD.html', context)
How i can get all the data in Interview table and also individual details of Recuirement, Candidate table in modal bootstrap 5
In for loop tag in django
<div class="row">
<div class="row">
<h1>Graphs</h1>
</div>
<div class="row">
<div class="col-lg-12" style="padding: 20px 60px 0 60px;">
<table class="table table-hover table-bordered">
<thead>
<tr class="table-dark">
<th scope="col">Id</th>
<th scope="col">Created_on</th>
<th scope="col">Recruiter</th>
<th scope="col">Requirement</th>
<th scope="col">Candidate</th>
<th scope="col">Interview_Mode</th>
<th scope="col">Data&Time_Interview</th>
<th scope="col">Interview_Status</th>
<th scope="col">Interview_Location</th>
<th scope="col">Comments</th>
<th scope="col">Last_updated</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for interview in Interview_data %}
<tr>
<th scope="row">{{interview.id}}</th>
<th scope="row">{{interview.Current_Date}}</th>
<th scope="row">{{interview.User}}</th>
<td>
{{interview.Recuirement}}
<div class="modal fade" id="Requirement" tabindex="-1" aria-labelledby="requirement" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="requirement">Requirement Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table">
<tbody>
<tr>
<th scope="row">ID</th>
<td>{{ interview.Recuirement.id }}</td>
</tr>
<tr>
<th scope="row">Company Name</th>
<td>{{ interview.Recuirement.Client_Info }}</td>
</tr>
<tr>
<th scope="row">Position</th>
<td>{{ interview.Recuirement.Position }}</td>
</tr>
<tr>
<th scope="row">Department</th>
<td>{{ interview.Recuirement.Department }}</td>
</tr>
<tr>
<th scope="row">Experience</th>
<td>{{ interview.Recuirement.From_Year }} Years {{ interview.Recuirement.To_Year }} Months</td>
</tr>
<tr>
<th scope="row">Notice Period</th>
<td>{{ interview.Recuirement.NoticePeriod }}</td>
</tr>
<tr>
<th scope="row">Salary Package</th>
<td>{{ interview.Recuirement.Salary_package}}</td>
</tr>
<tr>
<th scope="row">Location</th>
<td>{{ interview.Recuirement.Location }}</td>
</tr>
<tr>
<th scope="row">No of Openings</th>
<td>{{ interview.Recuirement.No_Of_Openings }}</td>
</tr>
<tr>
<th scope="row">Job Description</th>
<td>{{ interview.Recuirement.Job_Description }}</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</td>
<td><button type="button" style="border-radius: 30px;" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#Candidate">
{{interview.Candidate}}
</button>
<div class="modal fade" id="Candidate" tabindex="-1" aria-labelledby="candidate" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="candidate">Candidate Details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table">
<tbody>
<tr>
<th scope="row">id</th>
<td>{{ interview.Candidate.id }}</td>
</tr>
<tr>
<th scope="row">Current_Date</th>
<td>{{ interview.Candidate.Current_Date }}</td>
</tr>
<tr>
<th scope="row">Candidate_Name</th>
<td>{{ interview.Candidate.Candidate_name }}</td>
</tr>
<tr>
<th scope="row">Client</th>
<td>{{ interview.Candidate.Client_Info }}</td>
</tr>
<tr>
<th scope="row">Qualification</th>
<td>{{ interview.Candidate.Qualification }}</td>
</tr>
<tr>
<th scope="row">Experience</th>
<td>{{ interview.Candidate.Year }} Years {{ interview.Candidate.Months }} Months</td>
</tr>
<tr>
<th scope="row">Current_Salary</th>
<td>{{ interview.Candidate.Current_Salary }}</td>
</tr>
<tr>
<th scope="row">Current_Location</th>
<td>{{ interview.Candidate.Current_Location}}</td>
</tr>
<tr>
<th scope="row">Expected_Salary</th>
<td>{{ interview.Candidate.Expected_Salary }}</td>
</tr>
<tr>
<th scope="row">Preferred_Location</th>
<td>{{ interview.Candidate.Preferred_Location }}</td>
</tr>
<tr>
<th scope="row">Languages_Known</th>
<td>{{ interview.Candidate.Languages_Known }}</td>
</tr>
<tr>
<th scope="row">Marital_Status</th>
<td>{{ interview.Candidate.Marital_Status }}</td>
</tr>
<tr>
<th scope="row">Candidate_Notice_Period</th>
<td>{{ interview.Candidate.Candidate_Notice_Period }}</td>
</tr>
<tr>
<th scope="row">Email</th>
<td>{{ interview.Candidate.Email }}</td>
</tr>
<tr>
<th scope="row">Primary_Contact_No</th>
<td>{{ interview.Candidate.Primary_Contact_No }}</td>
</tr>
<tr>
<th scope="row">Secondary_Contact_No</th>
<td>{{ interview.Candidate.Secondary_Contact_No }}</td>
</tr>
<tr>
<th scope="row">Comments</th>
<td>{{ interview.Candidate.Comments }}</td>
</tr>
<tr>
<th scope="row">Update_Date</th>
<td>{{ interview.Candidate.Update_Date }}</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div></td>
<td>{{interview.Interview_Mode}}</td>
<td>{{interview.Date}}-{{interview.Time}}</td>
<span class="badge rounded-pill bg-primary">Primary</span>
<td>{{interview.Interview_status}}</td>
<td>{{i.Interview_Location}}</td>
<td>{{interview.Comments}}</td>
<td>{{interview.Update_Date}}</td>
<td>Edit</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>

How to transpose into the "same" column?

I have a table like
<table class="tg">
<tr>
<th class="tg-0lax">date</th>
<th class="tg-0lax">organic</th>
<th class="tg-0lax">referrer</th>
<th class="tg-0lax">direct</th>
</tr>
<tr>
<td class="tg-0lax">01.01.2019</td>
<td class="tg-0lax">12345</td>
<td class="tg-0lax">123</td>
<td class="tg-0lax">23</td>
</tr>
<tr>
<td class="tg-0lax">25.01.2019</td>
<td class="tg-0lax">23456</td>
<td class="tg-0lax">234</td>
<td class="tg-0lax">34</td>
</tr>
<tr>
<td class="tg-0lax">03.03.2019</td>
<td class="tg-0lax">34567</td>
<td class="tg-0lax">345</td>
<td class="tg-0lax">56</td>
</tr>
<tr>
<td class="tg-0lax">15.04.2019</td>
<td class="tg-0lax">45678</td>
<td class="tg-0lax">456</td>
<td class="tg-0lax">78</td>
</tr>
</table>
I want to get the data into this view, where all data are placed into the same three columns, not dependently of whether points in the first column are repeated:
<table class="tg">
<tr>
<th class="tg-0lax">type</th>
<th class="tg-0lax">source</th>
<th class="tg-0lax">date</th>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">12345</td>
<td class="tg-0lax">01.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">123</td>
<td class="tg-0lax">01.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">23</td>
<td class="tg-0lax">01.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">23456</td>
<td class="tg-0lax">25.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">234</td>
<td class="tg-0lax">25.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">34</td>
<td class="tg-0lax">25.01.2019</td>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">34567</td>
<td class="tg-0lax">03.03.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">345</td>
<td class="tg-0lax">03.03.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">56</td>
<td class="tg-0lax">03.03.2019</td>
</tr>
<tr>
<td class="tg-0lax">organic</td>
<td class="tg-0lax">45678</td>
<td class="tg-0lax">15.04.2019</td>
</tr>
<tr>
<td class="tg-0lax">referrer</td>
<td class="tg-0lax">456</td>
<td class="tg-0lax">15.04.2019</td>
</tr>
<tr>
<td class="tg-0lax">direct</td>
<td class="tg-0lax">78</td>
<td class="tg-0lax">15.04.2019</td>
</tr>
</table>
The "normal" transposing is pretty close to what I want, but even not exactly this, and I miss the point, how to pivot the data.
Another one example:
Got an error:
What I'm doing wrong? The formula is:
=ARRAYFORMULA({"type","source","date";SPLIT(TRANSPOSE(SPLIT(CONCATENATE(IF(B2:D<>"","♠"&B1:D1&"♦"&B2:D&"♦"&A2:A, )),"♠")),"♦")})
The line breaks are from the formula away - I've deleted them. Could the error cause be that my Google Spreadsheets used in Germany - formula language issue?
=ARRAYFORMULA({"type", "source", "date";
SPLIT(TRANSPOSE(SPLIT(CONCATENATE(IF(B2:D<>"",
"♠"&B1:D1&"♦"&B2:D&"♦"&A2:A, )), "♠")), "♦")})

Interval in Django template

I have an interval type field that contains hours and minutes in this format: "28:00".
But in my template, it is translated to "1 day, 4:00:00"
How can I keep this "28:00" in my template?
My template:
<table class="table table-bordered ">
<thead align="center">
<th class="text-center" scope="col">User</th>
<th class="text-center" scope="col">Week number</th>
<th class="text-center" scope="col">Total H</th>
</thead>
<tbody>
{% for tp in resume_h %}
<tr scope="row">
<td class="text-center col-md-1">{{ tp.user_name }}</td>
<td class="text-center col-md-1">{{ tp.num_semaine }}</td>>
<td class="text-center col-md-1">{{ tp.hours_total|linebreaksbr }}</td>
</tr>
{% endfor %}
</tbody>
</table>
My model:
class hours(models.Model):
user_name = models.CharField(max_length=50, blank=True, null=True)
num_semaine = models.IntegerField(("No:"),blank=True, null=True)
hours_total = models.TimeField(("H"),blank=True, null=True)
def __str__(self):
return str(self.user_name)
Thank you

Is there any way to save and HTML table including forms without creating a model in Django?

I have created a table with django forms in it. The forms do get data from the database, from two different models. Since this form has 42 fields consisting of 7 days and 6 shifts, i would love to save it as the table it is rendered. Is there any way to do this?
forms.py
class EditSchedule(forms.Form):
def __init__(self,*args,**kwargs):
super(EditSchedule, self).__init__(*args,**kwargs)
for k in range(1,8):
for i in range(1,7):
self.fields["S"+str(i)+"D"+str(k)] = forms.ChoiceField(choices=get_my_choices(i,k))
self.fields["S"+str(i)+"D"+str(k)].widget.attrs.update({"class":"form-control select2 select2-hidden-accessible"})
html file
<div class="box">
<form method="POST" action="">{% csrf_token %}
<div class="box-body">
<div class="table-container table-responsive">
<table class="table table-bordered table-hover dataTable" role="grid" >
<thead>
<tr>
<th class = "shicht"><h3>Schicht</h3></th>
<th class = "montag"><h3>Montag</h3></th>
<th class = "dienstag"><h3>Dienstag</h3></th>
<th class = "mittwoch"><h3>Mittwoch</h3></th>
<th class = "donnerstag"><h3>Donnerstag</h3></th>
<th class = "freitag"><h3>Freitag</h3></th>
<th class = "samstag"><h3>Samstag</h3></th>
<th class = "sonntag"><h3>Sonntag</h3></th>
</tr>
</thead>
<tbody>
<tr class="even">
<td class="shicht">Schicht 1</td>
<td class="montag">{{ form.S1D1 }}</td>
<td class="dienstag">{{ form.S1D2 }}</td>
<td class = "Mittwoch">{{ form.S1D3 }}</td>
<td class = "donnerstag">{{ form.S1D4 }}</td>
<td class = "freitag">{{ form.S1D5 }}</td>
<td class ="samstag">{{ form.S1D6 }}</td>
<td class ="sonntag">{{ form.S1D7 }}</td>
</tr>
<tr class="odd">
<td class="shicht">Schicht 2</td>
<td class="montag">{{ form.S2D1 }}</td>
<td class="dienstag">{{ form.S2D2 }}</td>
<td class = "Mittwoch">{{ form.S2D3 }}</td>
<td class = "donnerstag">{{ form.S2D4 }}</td>
<td class = "freitag">{{ form.S2D5 }}</td>
<td class ="samstag">{{ form.S2D6 }}</td>
<td class ="sonntag">{{ form.S2D7 }}</td>
</tr>
<tr class="even">
<td class="shicht">Schicht 3</td>
<td class="montag">{{ form.S3D1 }}</td>
<td class="dienstag">{{ form.S3D2 }}</td>
<td class = "Mittwoch">{{ form.S3D3 }}</td>
<td class = "donnerstag">{{ form.S3D4 }}</td>
<td class = "freitag">{{ form.S3D5 }}</td>
<td class ="samstag">{{ form.S3D6 }}</td>
<td class ="sonntag">{{ form.S3D7 }}</td>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Save">
You can use raw queries for this.
For capture the form filds you can use the "clean" methods in the base form class see forms validation

Code after CFInclude seems to disappear or is not rendered

Having some issues with a ColdFusion application here. I'm trying to add in a <cfinclude template="header.cfm"/> and it renders correctly however the rest of the cf code seems to disappear, not sure if its not being rendered or just not showing up because of the cfinclude statement running. This is for a page header I'm trying to insert.
Is there a way to insert the cfincludes and have it stop so the rest of the page can process? Does my question make sense?
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<!-- fwtable fwsrc="header.png" fwbase="default.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="1" -->
<tr>
<td><img name="grantpro" src="images/grantpro.gif" width="411" height="80" border="0" alt=""></td>
<td><img name="gpimage" src="images/gpimage.jpg" width="189" height="80" border="0" alt=""></td>
</tr>
<tr>
<td colspan="2" align="center">
<table width="599px" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td colspan="4"><div align="center"><font size="5"><strong>FDC Menu</strong></font></div></td>
</tr>
<td colspan="3"><strong>FDC Pending Proposals:</strong></td>
</tr>
<tr>
<td> </td>
<td colspan="2">By Applicant Name</td>
</tr>
<tr>
<td> </td>
<td colspan="2">By Grant Type</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="3"><strong>FDC Funded Proposals:</strong></td>
</tr>
<tr>
<td> </td>
<td colspan="2"><strong><em>Current Year</em></strong></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>By Applicant Name</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>By Grant Type</td>
</tr>
<tr>
<td> </td>
<td colspan="2"><em><strong>Prior Years</strong></em></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>By Applicant Name </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>By Grant Type</td>
<cfinclude template="cssmenu/header.cfm"/>
</table>
<p align="center"><strong>Logout</strong></p> </td>
The following code shows where the problem is
<tr>
<td> </td>
<td> </td>
<td>By Grant Type</td>
<cfinclude template="cssmenu/header.cfm"/>
</table>
Solution 1:
This is the recommended solution
The <cfinclude> probably should be moved outside of the </table>
Solution 2:
cssmenu/header.cfm would need to finish the current table row and start an new one. This is not recommended. It is not modular at all.
</tr>
<tr>
<td colspan="3">
... Content goes here ...
</td>
</tr>
You are missing a </tr> before the <cfinclude>. Also it seems like an odd place to include a header, rather add another table row and td and include the header inside of the <td> not in between the table code as this is causing it to break.