2
Hi, I’m new to Django and I have the following problem, I have two classes in Django one of them is :
class Apps(models.Model):
id = models.UUIDField(db_column='ID', primary_key=True) # Field name made lowercase.
name = models.CharField(db_column='Name', max_length=255) # Field name made lowercase.
appid = models.CharField(db_column='AppId', max_length=500, blank=True, null=True) # Field name made lowercase.
publishtime = models.DateTimeField(db_column='PublishTime') # Field name made lowercase.
published = models.BooleanField(db_column='Published') # Field name made
class Meta:
managed = False
db_table = 'Apps'
And the other is :
class Executionresults(models.Model):
id = models.UUIDField(db_column='ID', primary_key=True) # Field name made lowercase.
taskid = models.UUIDField(db_column='TaskID') # Field name made lowercase.
executionid = models.UUIDField(db_column='ExecutionID') # Field name made lowercase.
appid = models.UUIDField(db_column='AppID') # Field name made lowercase.
executingnodeid = models.UUIDField(db_column='ExecutingNodeID') # Field name made lowercase.
status = models.IntegerField(db_column='Status') # Field name made
I would like to know how to compare two values, if the "appid" of the table "Apps" is equal to the "appid" of the table "Executionresults" it has to return me the "name" of the table "Apps".
I tried to do this live in index.html, but to no avail.
<table class="table table-striped up">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Task ID</th>
<th scope="col">Inicio</th>
<th scope="col">Fim</th>
<th scope="col">Nome App</th>
<th scope="col">status</th>
</tr>
</thead>
<tbody>
{% for exe in executionresults %}
{% for app in apps %}
<tr>
<th scope="row"></th>
<td>{{ exe.taskid }}</td>
<td>{{ exe.starttime }}</td>
<td>{{ exe.stoptime }}</td>
{% if exe.appid == app.targetappid %}
<td>{{ return app.name }}</td>
{%endif%}
{% if exe.status == 1 %}
<td style="text-align: center;"class="alert alert-danger" role="alert">Desencadeado <i class="fa fa-check" style="font-size:16px"></i></td>
{%elif exe.status == 2 %}
<td style="text-align: center;"class="alert alert-success" role="alert">Iniciado <i class="fa fa-check" style="font-size:16px"></i></td>
{%elif exe.status == 3 %}
<td style="text-align: center;"class="alert alert-success" role="alert">Na fila <i class="fa fa-check" style="font-size:16px"></i></td>
{%elif exe.status == 4 %}
<td style="text-align: center; "class="alert alert-warning" role="alert">Abortar iniciado <i class="fa fa-exclamation" style="font-size:20px"></i></td>
{%elif exe.status == 5 %}
<td style="text-align: center; "class="alert alert-warning" role="alert">Abortando <i class="fa fa-exclamation" style="font-size:20px"></i></td>
{%elif exe.status == 6 %}
<td style="text-align: center;"class="alert alert-danger" role="alert">Abortado <i class=" fa fa-close" style="font-size:20px"></i></td>
{% elif exe.status == 7 %}
<td style="text-align: center;"class="alert alert-success" role="alert">Finalizado com sucesso <i class="fa fa-check" style="font-size:16px"></i></td>
{%elif exe.status == 8 %}
<td style="text-align: center;"class="alert alert-danger" role="alert">Falha! <i class=" fa fa-close" style="font-size:20px"></i></td>
{%elif exe.status == 9 %}
<td style="text-align: center; "class="alert alert-warning" role="alert">Pulou <i class="fa fa fa-exclamation" style="font-size:20px"></i></td>
{%elif exe.status == 10 %}
<td style="text-align: center;"class="alert alert-danger" role="alert">Tente novamente <i class="fa fa-close" style="font-size:20px"></i></td>
{%elif exe.status == 11 %}
<td style="text-align: center;"class="alert alert-danger" role="alert">Erro! <i class=" fa fa-close" style="font-size:20px"></i></td>
{%elif exe.status == 12 %}
<td style="text-align: center;"class="alert alert-danger" role="alert">Restabelecer <i class=" fa fa-close" style="font-size:20px"></i></td>
{%else%}
<td>{{ exe.status }}</td>
{%endif%}
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
My ultimate goal is to bring the tasks from the Executionresults table, but this table does not show the name of the app, and I need to show it to the user, so I need to make this union of tables.
Thank you so much for your help, I’ll make these adjustments and see what I can do.
– Gabriel Santos
Hello Fabíola, it would be possible to perform this configuration inside the view ?
– Gabriel Santos
A foreing key (Restaurant = models.Foreignkey(Restaurant, on_delete=models.CASCADE)) has to be in the model. In the view you send the Execution Results objects to your html template:
return render(request, 'index.html', {'executionresults': Executionresults.objects.all()})
– Fabíola
I edited the answer, I don’t know if it was very clear so anything just talk :)
– Fabíola
Thanks again for the return Fabíola, just one more question, when I put this field in the models I can’t access the page anymore, I get an error . " column Executionresults.appidexe_id does not exist LINE 1: ...ults"." Taskid", "Executionresults"." Executionid", "Execution... " Even after giving a migrate and makemigrations the error continues.
– Gabriel Santos
I managed to solve Fabíola, I just reset my Migrations and it worked, I thank you again for your attention.
– Gabriel Santos