我有一个名为仪表板的模型。仪表板有一个名为model_name的字段,它只是一个charfield。我还有一个名为Dashboard_Field的字段,我试图在服务器最初启动时进行填充。我通过获取仪表板和模型来做到这一点。但是我收到错误消息“ ManyToOneRel对象没有属性详细名称”
for s_dashboard in dashboard:
for models in model
fields = model._meta.get_fields()
for sfield in fields:
if sdashboard.model_name == model._meta.verbose_name:
field = Dashboard_Field.objects.create(field=sfield.verbose_name, dashboard=sdashboard)
class Dashboard(models.Model):
model_name = models.CharField(max_length=1000, default='', null=True, verbose_name="Model Name")
def __str__(self):
return 'Dashboard ' + str(self.id)
class Dashboard_Field(models.Model):
dashboard = models.ForeignKey(Dashboard, on_delete=models.CASCADE, null=False)
field_name = models.CharField(max_length=100, null=True)
class Filter(models.Model):
dashboard = models.ForeignKey(Dashboard, on_delete=models.CASCADE, null=False)
dashboard_field = ChainedForeignKey(Dashboard_Field, chained_field="dashboard", chained_model_field="dashboard", show_all=False, auto_choose=True, sort=True, null=True)