开发者

django foreign key admin interface and models structure

(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.


My suggestion for your customer's request

He wants one button (Add product) then pop-up windows appears, with fields: product, quantity, unit price. He fills them, press OK.

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.

Or I need to write my own widget or smth like that?

Yes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜