Why are the items not appearing in the table?
I'm creating a point of sale using Django, a part arrived here that the items are not showing up, since I already registered them... Could someone help me?
A note: I'm Brazilian, my code is in the language, but I think there will be no problems.
Here's the codes:
This is the models part, which is inside the 'registration' app. I want this information to appear in another app called 'pages' inside, of course, the folder called 'templates'..
from django.db import models
class ListaProdutos(models.Model):
nome_produto = models.CharField(max_length=50, verbose_name='Produto')
quantidade_produto = models.IntegerField(verbose_name='Qntd.')
custo_venda = models.CharField(max_length=10, verbose_name='Custo/Venda')
fornecedor = models.CharField(max_length=50, verbose_name='Fornecedor')
data_adicao = models.DateTimeField(verbose_name='Data de Adição')
def __str__(self):
return "{} {} {} {} {}".format(self.nome_produto, self.quantidade_produto, self.custo_venda, self.fornecedor, self.data_adicao)
class ListaDespesas(models.Model):
nome_despesa = models.CharField(max_length=50, verbose_name='Despesas')
quantidade_despesa = models.CharField(max_length=50, verbose_name='Qntd.')
custo = models.IntegerField(verbose_name='Custo')
tipo_gasto = models.CharField(max_length=50, verbose_name='Tipo de Gasto')
data_atualizacao = models.DateTimeField(verbose_name='Data de Atualização')
def __str__(self):
return "{} {} {} {} {}".format(self.nome_despesa, self.quantidade_despesa, self.custo, self.tipo_gasto, self.data_atualizacao)
Still in the 'registration' app, only in the urls part:
from django.urls import path
from .views import ProdutoCreate, DespesaCreate
from .views import ProdutoUpdate, DespesaUpdate
from .views import ProdutoDelete, DespesaDelete
from .views import ProdutoList, DespesaList
urlpatterns = [
path('cadastrar/produto', ProdutoCreate.as_view(), name='cadastrar-produto'),
path('cadastrar/despesas', DespesaCreate.as_view(), name='cadastrar-despesa'),
path('editar/produto/<int:pk>/', ProdutoUpdate.as_view(),name='editar-produto'),
path('editar/despesa/<int:pk>', DespesaUpdate.as_view(),name='editar-despesa'),
path('excluir/produto/<int:pk>/', ProdutoDelete.as_view(),name='excluir-produto'),
path('excluir/despesa/<int:pk>', DespesaDelete.as_view(),name='excluir-despesa'),
path('gastos/',ProdutoList.as_view(), name='lista-produto'),
path('gastos/',DespesaList.as_view(), name='lista-despesa'),
]
In 'register' in the views part:
from multiprocessing import context
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView
from .models import ListaDespesas, ListaProdutos
from django.urls import reverse_lazy
""" Views """
class ProdutoCreate(CreateView):
model = ListaProdutos
fields = ['nome_produto', 'quantidade_produto', 'custo_venda', 'fornecedor', 'data_adicao']
template_name = 'cadastro/form.html'
success_url = reverse_lazy('vendas')
class DespesaCreate(CreateView):
model = ListaDespesas
fields = ['nome_despesa', 'quantidade_despesa', 'custo', 'tipo_gasto', 'data_atualizacao']
template_name = 'cadastro/form.html'
success_url = reverse_lazy('vendas')
""" Update """
class ProdutoUpdate(UpdateView):
model = ListaProdutos
fields = ['nome_produto', 'quantidade_produto', 'custo_venda', 'fornecedor', 'data_adicao']
template_name = 'cadastro/form.html'
success_url = reverse_lazy('vendas')
class DespesaUpdate(UpdateView):
model = ListaDespesas
fields = ['nome_despesa', 'quantidade_despesa', 'custo', 'tipo_gasto', 'data_atualizacao']
template_name = 'cadastro/form.html'
success_url = reverse_lazy('vendas')
""" Delete """
class ProdutoDelete(DeleteView):
model = ListaProdutos
template_name = 'cadastro/form-excluir.html'
success_url = reverse_lazy('vendas')
class DespesaDelete(UpdateView):
model = ListaDespesas
template_name = 'cadastro/form-excluir.html'
succes_url = reverse_lazy('vendas')
""" Lista """
class ProdutoList(ListView):
model = ListaProdutos
template_name = 'paginas/gastos.html'
class DespesaList(ListView):
model = ListaDespesas
template_name = 'paginas/gastos.html'
Finally, inside the 'paginas' app, inside the templates folder, inside the 'pages' directory, the 'gastos.html' template:
{% extends 'paginas/modelo.html' %}
{% load static %}
{% block titulo %}
<title>PDV|Gastos</title>
{% endblock %}
{% block conteudo %}
<div class="home_content">
<div class="conteudo_pagina">
<div class="table-responsive">
<table class="table table-striped">
<tr>
<th>Código</th>
<th>Produto</th>
<th>Qntd.</th>
</tr>
{% for produto in object_list %}
<tr>
<td>{{ produto.pk }}</td>
<td>{{ produto.nome_produto }}</td>
<td>{{ produto.quantidade_produto }}</td>
</tr>
{% empty %}
<tr>
<td colspan="3">Nenhum campo registrado</td>
</tr>
{% endfor %}
<div class="table-responsive">
<table class="table table-striped">
<tr>
<th>Despesa</th>
<th>Qntd.</th>
<th>Custo</th>
</tr>
{% for despesa in object_list %}
<tr>
<td>{{ despesa.nome_despesa }}</td>
<td>{{ despesa.quantidade_despesa }}</td>
<td>{{ despesa.custo }}</td>
</tr>
{% empty %}
<tr>
<td colspan="3">Nenhum campo registrado</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
Here is the image from the website: enter image description here