3
In my code Python I create an object called status as follows:
In Forms/status.py
class StatusForm(forms.ModelForm):
class Meta:
model = Status
fields = ('status', 'posicao')
widget = {
'status': forms.TextInput(attrs={'class': 'form-control'}),
'posicao': forms.TextInput(attrs={'class': 'form-control'}),
}
labels = {
'status': _('Descrição'),
'posicao': _('Posição da coluna na navegação'),
}
In models/status.py
class Status(models.Model):
status = models.CharField(max_length=32)
posicao = models.IntegerField(default=1)
class Meta:
verbose_name = "Status"
permissions = (
("view_status", "Can view status"),
)
And the following code in views/status.py
class AdicionarStatusView(AdicionarOutrosBaseView):
form_class = StatusForm
model = Status
success_url = reverse_lazy('cadastro:addstatusview')
permission_codename = 'add_status'
class StatusView(CustomListView):
model = Status
template_name = 'cadastro/status_list.html'
context_object_name = 'all_status'
success_url = reverse_lazy('cadastro:listastatusview')
permission_codename = 'view_status'
In templates/register/status_list.html, where is the table for me to see the status that have already been created, I do the following:
<div class="table-responsive">
<table id="lista-database" >
<thead>
<tr>
<th>#ID</th>
<th>Descrição</th>
<th>Posição na Navegação</th>
</tr>
</thead>
<tbody>
{% for status in all_status %}
<td>{{status.id}}</td>
<td>{{status.status}}</td>
<td>{{status.posicao_navegacao}}</td>
{% endfor %}
</tbody>
</table>
</div>
I mean, in my code html with the table of the entire list of status, in order to access the id of status just let me know {{status.id}} within a loop. Now I need to access that same information in another file html, called index.html, for this I tried to do this way inside views/status.py:
class StatusListEmNavegacaoView(CustomListView):
model = StatusVenda
template_name = 'crm/navegacao/index.html'
context_object_name = 'all_status'
success_url = reverse_lazy('crm:navegacaoview')
permission_codename = 'view_status'
But by creating the loop inside the archive index.html I’m not trying to get any results.
I’m probably doing it incorrectly. In the table of status is working, but in another file not. All importare correct. What is the proper way for me to access my object status in another file html?