AttributeError on Django
<p>I'm stuck with (I think) a dummy error on Django that I can't find where it's the fault.</p>

<p>On "catalog/models.py" I have (it connects to a MySQL database):</p>

<pre><code>from django.db import models

class Application(models.Model):
    nameApp = models.CharField(max_length=50)
    tarification = models.ForeignKey(Tarification)
</code></pre>

<p>Then, I'm using <em>django-tables2</em> (<a href="https://django-tables2.readthedocs.io/en/latest/pages/table-data.html" rel="nofollow">Doc to fill tables</a>) to make tables on Django, so on my <em>tables.py</em> I have:</p>

<pre><code>import django_tables2 as tables
from catalog.models import AppCost, Application, Tarification


class BillTable(tables.Table):
    class Meta:
        appName = Application.nameApp
        userApp = AppCost.userApp
        tarifName = Tarification.nameTarif
        tarifCost = Tarification.cost
        startTime = AppCost.startTime
        finishTime = AppCost.finishTime
        totalCost = AppCost.totalCost
        # add class="paleblue" to &lt;table&gt; tag
        attrs = {'class': 'paleblue'}
</code></pre>

<p>And I get an error when I render my website:</p>

<pre><code>type object 'Application' has no attribute 'nameApp'
</code></pre>

<p>On the line <code>appName = Application.nameApp</code> from <em>BillTable</em></p>

<p>But, looking at "Database" window on <em>Pycharm</em> I see the table schema and it's:</p>

<ul>
<li>catalog_application

<ul>
<li>id</li>
<li>tarification_id</li>
<li>nameApp</li>
<li>other stuff</li>
</ul></li>
</ul>

<p>And looking with MySQL Workbench the schema looks the same. So, why I'm getting this error?</p>

<p>Regards.</p>

<p>As Daniel Roseman mentioned above, the code you might looking for is below, it does not need a new model:</p>

<pre><code>import django_tables2 as tables
from catalog.models import AppCost, Application, Tarification

class AppCostTable(tables.Table):
    userApp = tables.Column()
    startTime = tables.Column()
    finishTime = tables.Column()
    totalCost = tables.Column()

    class Meta:
        model = AppCost

class ApplicationTable(tables.Table):
    appName = tables.Column(accessor='nameApp')
    class Meta:
        model = Application

class TarificationTable(tables.Table):
    tarifName = tables.Column(accessor='nameTarif')
    tarifCost = tables.Column(accessor='cost')
    class Meta:
        model = Tarification


class BillTable(AppCostTable, ApplicationTable, TarificationTable, tables.Table):
    pass
</code></pre>

<p>If you do not mind to have another model, then inside your <strong>catalog.models</strong> you can add a new Bill model:</p>

<pre><code>class Bill(models.Model):
    application = models.ForeignKey('Application')
    appcost = models.ForeignKey('AppCost')
    tarification = models.ForeignKey('Tarification')
</code></pre>

<p>In your table file:</p>

<pre><code>from catalog.models import Bill

class BillTable(tables.Table):
    appName = tables.Column(accessor='application.nameApp')
    tarifName = tables.Column(accessor='tarification.nameTarif')
    tarifCost = tables.Column(accessor='tarification.cost')
    userApp = tables.Column(accessor='appcost.userApp')
    startTime = tables.Column(accessor='appcost.startTime')
    finishTime = tables.Column(accessor='appcost.finishTime')
    totalCost = tables.Column(accessor='appcost.totalCost')


    class Meta:
        model = Bill
</code></pre>

python mysql django