class PurchaseOrder(models.Model): po_number = models.IntegerField(default=get_po_number, unique=True) po_date = models.DateField() invoice_number = models.ForeignKey(Invoice, on_delete=models.CASCADE)
....
class PurchaseOrderItem(models.Model): po_number_fk = models.ForeignKey(PurchaseOrder, on_delete=models.CASCADE) qty = models.IntegerField() unit = models.CharField(max_length=100, blank=True, null=True) description = models.CharField(max_length=255) unit_price = models.DecimalField(max_digits=6, decimal_places=2) amount = models.DecimalField(max_digits=6, decimal_places=2)
class PurchaseOrderTotal(models.Model): po_number_fk = models.ForeignKey(PurchaseOrder, on_delete=models.CASCADE) subtotal = models.DecimalField(max_digits=6, decimal_places=2) tax = models.DecimalField(max_digits=6, decimal_places=2, default="7.82") shipping = models.DecimalField(max_digits=6, decimal_places=2) other = models.DecimalField(max_digits=6, decimal_places=2) total = models.DecimalField(max_digits=6, decimal_places=2)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc6a1cb9-0770-49d9-9c89-92d1f947e718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class PurchaseOrderDetailView(LoginRequiredMixin, TemplateView): #context_object_name = "po" #model = PurchaseOrder template_name = 'financial/purchase_orders/purchase_order_detail.html'
def get_context_data(self, **kwargs): context = super(PurchaseOrderDetailView, self).get_context_data(**kwargs) context['purchase_order'] = PurchaseOrder.objects.get() context['item'] = PurchaseOrderItem.objects.all() return context
Andréas
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
path('purchase_order/<int:pk>/', views.PurchaseOrderDetailView.as_view(), name='purchase-order-detail'),
class PurchaseOrderDetailView(LoginRequiredMixin, DetailView):
model = PurchaseOrder
template_name = 'financial/purchase_orders/purchase_order_detail.html'
def get_object(self, queryset=None):Now the reason for this is that you need to write a lot less code. Another question is why you don't use the default id field on the purchase order? Because if you did, you wouldn't need to add the get_object() method to the detail view. Also if you follow the correct layout of your templates (in this case it should be called purchaseorders/purchaseorder_defailt.html and you don't need to add a template name either). Essentially the code for your detail view could be only:
return self.get_queryset().get(po_number=self.kwargs.get('pk'))
class PurchaseOrderDetailView(LoginRequiredMixin, DetailView):If you follow the guidelines that the detail view requires :-)
model = PurchaseOrder
{{ purchaseorder.info }}
{% for item in purchaseorder.purchaseorderitem_set %}
{{ item.qty }}
{% endfor %}
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ecceb7e6-b42b-4294-b56c-ae02626c40e3%40googlegroups.com.