How to get a django template to pull information from two different models?

前端 未结 1 1204
有刺的猬
有刺的猬 2021-01-26 12:29

I am coding a basic django application that will show a table of current store sales, based off of information from a MariaDB database.

The data is entered into the dat

相关标签:
1条回答
  • 2021-01-26 13:00

    The storeid field on the ShowroomData model of actually a foreign key. So you should declare it as such:

    class ShowroomData(models.Model):
        store = models.ForeignKey("Stores", db_column="storeid")
    

    Now you can follow that fk in your template. Assuming current_showroom is a queryset of ShowroomData instances:

            {% for store in current_showroom %}
              <tr>
                <td>{{ store.storeid }}</td>
                <td>{{ store.store.name }}</td>
              </tr>
            {% endfor %}
    
    0 讨论(0)
提交回复
热议问题