我被Django的一个错误缠住了(我想),我找不到错误的地方。你知道吗
关于“目录”/型号.py“我有(它连接到MySQL数据库):
from django.db import models
class Application(models.Model):
nameApp = models.CharField(max_length=50)
tarification = models.ForeignKey(Tarification)
然后,我使用django-tables2(Doc to fill tables)在django上生成表,在我的表格.py我有:
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 <table> tag
attrs = {'class': 'paleblue'}
当我呈现我的网站时出现了一个错误:
type object 'Application' has no attribute 'nameApp'
在BillTable的appName = Application.nameApp
行上
但是,查看Pycharm上的“数据库”窗口,我看到了表模式,它是:
使用MySQL Workbench,模式看起来是一样的。那么,为什么我会犯这个错误呢?你知道吗
敬礼。你知道吗
正如Daniel Roseman上面提到的,您可能要查找的代码如下,它不需要新的模型:
如果您不介意换一个型号,那么在目录.模型您可以添加新的帐单模型:
在表文件中:
你对如何使用django表很困惑。您需要在元类中指定一个模型,然后只需使用
fields
属性添加该模型中的字段列表(作为字符串)即可显示。不能只指定三个任意模型中的字段。你知道吗相关问题 更多 >
编程相关推荐