0

I am using Django and PostgreSQL. I have inserted some data into the models array field. My models are like

class PurchaseInvoice(models.Model):
    invoice = models.CharField(max_length=20)
    date = models.DateField(default=date.today)
    product_name = ArrayField(models.CharField(max_length=500))
    price = ArrayField(models.CharField(max_length=300))
    quantity = ArrayField(models.CharField(max_length=200))
    amount = ArrayField(models.CharField(max_length=300))

I have inserted data successfully, but when I try to query my data I get like ["['LNB Inverto', 'Dish']"]. I want to view my data in an HTML table. My views.py file is as the following:

def purchaseDetails(request,pk):
    invo_data = PurchaseInvoice.objects.filter(invoice=pk)
    return render(request,'purchase/invoice_details.html',{'invoice':invo_data})

And my HTML tables like:

{% for data in invoice %}
    <tr>
        <td>{{data.product_name}}</td>
        <td>{{data.price}}</td>
        <td>{{data.quantity}}</td>
    </tr>
{% endfor %}

2 Answers 2

1
{% for data in invoice %}
    <tr>
        <td>
            {% for name in data.product_name %}
                {{ name }}
            {% endfor %}
        </td>
        <td>{{ data.price }}</td>
        <td>{{ data.quantity }}</td>
    </tr>
{% endfor %}
happy coding :)
Sign up to request clarification or add additional context in comments.

1 Comment

I got ['LNB Inverto', 'Dish']
0

Try to the following code. Your code is almost 100% right, I think, but I don’t know why the query returns like this: ["['LNB Inverto', 'Dish']"].

PurchaseInvoice.objects.all().filter(invoice=pk)

So try to do this query. Maybe your problem will be solved.

1 Comment

ca you project file with me i check it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.