简体   繁体   English

如何通过 django 管理面板添加列

[英]How to add columns through django admin panel

I have a table named tableA with columns "name" and "age" built using model.py .我有一个名为 tableA 的表,其中包含使用model.py构建的"name""age" model.py

Now I wanted to add another column like "gender" but this time not by changing model.py but directly through admin panel.现在我想添加另一列,如"gender"但这次不是通过更改 model.py 而是直接通过管理面板。

I know that admin panel allows to add values to the existing table but i wanted to add a feature where we can add columns too through the admin panel and not by hardcoding in model.py我知道管理面板允许向现有表添加值,但我想添加一个功能,我们也可以通过管理面板添加列,而不是通过在model.py硬编码

So is it possible?那么有可能吗?

Check this answer about having dynamic models.检查这个关于拥有动态模型的答案 I prefer JsonField to save data when I don't know the complete structure of model.当我不知道模型的完整结构时,我更喜欢 JsonField 来保存数据。

Actually you can create a view, which one connects to DB and you can write there a creating of any column for this table using raw SQL.实际上,您可以创建一个视图,该视图连接到数据库,您可以在那里使用原始 SQL 为该表编写任何列的创建。
But it's an awful way.但这是一种可怕的方式。 In future, you will get an enormous count of different troubles.将来,您将遇到大量不同的麻烦。
I'd better say: it's not possible.我最好说:这是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM