I'm trying to create a tab with the django-suit extension to view a quote and list all the quote items. I'm not quite sure how to do this within the django-suit extension as I knwo nromally I would use the {% for items in x %}
type templating code.
If anyone has any experience working with this extension and accomplishing this task, or if perhaps I can do it some other way, passing the primary key using original.pk
that would be great.
models.py
from django.db import models
class Quote(models.Model):
description = models.CharField(max_length=200)
date = models.DateField('Date Issued')
client = models.ForeignKey('organizations.Contact')
gst = models.BooleanField(default=True, verbose_name='GST Applicable')
assigned = models.BooleanField(default=True, verbose_name='Quote Assigned')
notes = models.TextField(blank=True)
def __str__(self):
return self.date.__str__().replace("-", "") + "-" + self.id.__str__().zfill(3)
class QuoteItem(models.Model):
order = models.PositiveIntegerField() # For Suit order sorting
invoice = models.ForeignKey(Quote)
description = models.CharField(max_length=200)
quantity = models.IntegerField(default=0)
price = models.DecimalField(max_digits=9, decimal_places=2)
def __str__(self):
return self.description
view_quote.html
<h2 class="legend">View Invoice
</h2><br>
{% if original.pk %}
<span>Invoice Information</span>
<table class="table-overview">
<tr>
<th>Invoice ID</th>
<td>
{{ original }}
</td>
</tr>
<tr>
<th>Description</th>
<td>
{{ original.description }}
</td>
</tr>
<tr>
<th>Client</th>
<td>
{{ original.client }}
</td>
</tr>
<tr>
<th>Notes</th>
<td>
{{ original.notes }}
</td>
</tr>
</table>
<span>Invoice Items</span>
<table class="table-overview">
<tr>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
{% for items in original.quoteitems %}
<tr>
<td>
{{ items.description }}
</td>
<td>
{{ items.price }}
</td> <td>
{{ items.quantity }}
</td> <td>
{{ items.total }}
</td>
</tr>
{% endfor %}
</table>
{% else %}
Item is not saved yet
{% endif %}
Had to change models.py with related_name
and view_quote.html