Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created January 30, 2023 20:30
Show Gist options
  • Save rg3915/a1670ab42ebd0e0404a561b8f743f04c to your computer and use it in GitHub Desktop.
Save rg3915/a1670ab42ebd0e0404a561b8f743f04c to your computer and use it in GitHub Desktop.
Aplicando filtros por Inquilino

O importante é aplicar o filtro corretamente.

<table class="table">
<thead>
<tr>
<th>Título</th>
<th>Inquilino</th>
</tr>
</thead>
<tbody id="expenseTbody">
{% for object in nfe_identifica %}
<tr>
<td>{{ object.titulo }}</td>
<td>{{ object.inquilino }}</td>
</tr>
{% endfor %}
<tr>
<td>--------------</td>
</tr>
{% for object in nfe_icms %}
<tr>
<td>{{ object.titulo }}</td>
<td>{{ object.inquilino }}</td>
</tr>
{% endfor %}
</tbody>
</table>
from django.db import models
from django.contrib.auth.models import User
class Inquilino(models.Model):
nome = models.CharField('nome', max_length=100)
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
)
class Meta:
ordering = ('nome',)
verbose_name = 'Inquilino'
verbose_name_plural = 'Inquilinos'
def __str__(self):
return f'{self.nome}'
class NfeIdentifica(models.Model):
titulo = models.CharField('título', max_length=100)
inquilino = models.ForeignKey(
Inquilino,
on_delete=models.CASCADE,
)
class Meta:
ordering = ('titulo',)
def __str__(self):
return f'{self.titulo}'
class NfeIcms(models.Model):
titulo = models.CharField('título', max_length=100)
inquilino = models.ForeignKey(
Inquilino,
on_delete=models.CASCADE,
)
class Meta:
ordering = ('titulo',)
def __str__(self):
return f'{self.titulo}'
from django.shortcuts import render
from .models import Inquilino, NfeIdentifica, NfeIcms
def inquilino_list(request):
template_name = 'imobiliaria/inquilino_list.html'
user = request.user
inquilino = Inquilino.objects.filter(user=user).first()
nfe_identifica = NfeIdentifica.objects.filter(inquilino=inquilino)
nfe_icms = NfeIcms.objects.filter(inquilino=inquilino)
context = {
'nfe_identifica': nfe_identifica,
'nfe_icms': nfe_icms,
}
return render(request, template_name, context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment