django 外键管理界面和模型结构
(所有代码都是某种伪代码,只是为了更好地阅读 我有一个发票模型:
class Invoice(models.Model):
// many fields here
我需要将一些产品(包含单位价格和数量字段)附加到该发票,因此我制作了附加表格:
class InvoiceProduct(models.Model):
product = models.ForeignKey
quantity = models.IntegerField
unit_price = models.DecimalField
invoice = models.ForeignKey(Invoice)
所以,这几乎是第一个问题 - «可以做得更好吗? »
我的第二个问题是,在 django admin 中我通过内联管理这些模型: 屏幕截图 但我的客户却不这么想。他想要一个按钮(添加产品),然后会出现弹出窗口,其中包含以下字段: 产品、数量、单价。他填满它们,然后按“确定”。然后弹出窗口关闭,主窗体中出现“产品字段”行。 我想我需要覆盖管理表单模板吗?或者我需要编写自己的小部件或类似的东西?
对不起我的英语。
(All code is some kind of pseudocode, just for better reading
I have an Invoice model:
class Invoice(models.Model):
// many fields here
I need to attach some products (with price for unit, and quantity fields) to this invoice, so I made additional table:
class InvoiceProduct(models.Model):
product = models.ForeignKey
quantity = models.IntegerField
unit_price = models.DecimalField
invoice = models.ForeignKey(Invoice)
So, this is almost first question — «Could it be done better way?»
My second problem is, that in django admin I have manage these models by inlines:
Screenshot
But my customer wants otherwise. He wants one button (Add product) then pop-up windows appears, with fields:
product, quantity, unit price. He fills them, press OK. Then pop-up window closes and line with "product fields" appears in main form.
I suppose I need override admin form template? Or I need to write my own widget or smth like that?
Sorry for my English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对您客户要求的建议
不要为此使用 django admin。仅将其用于想要几乎直接访问数据的人。在我的脑海中,我认为它仅比数据库本身高出半步。这意味着它不适合用户而不适合管理员。
是的
My suggestion for your customer's request
Do NOT use the django admin for this. Only use it for people who want to access the data almost directly. In my head I see it just one half step up from the database itself. This means it is not suitable for users rather than administrators.
Yes