Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are nested inline forms possible in Django Admin models?

Tags:

mysql

django

I was about to ask essentially the same question as this one. However, since no one answered it, I'll assume that nested inline forms aren't possible.

So instead I'll just ask how you would approach designing something like this in Django:

A retailer sells clothing. Each sweater design has a Style number. This style is available in different fabrics and different colors, hence you need a Style Table and a Product Table to handle each variation of sweater. (e.g. there could be a blue cotton sweater, blue nylon sweater, green cotton sweater, etc...) This would contain a Foreign Key into a Fabric Table and a Color Table.

But we need pictures! Each product variation can have one or more pictures. So we add an Image Table with a Foreign Key to the product table.

Without nested inlines, the only way I can think of to present this in the CMS is to have client add a style first, along with the subordinate products inline. Then when done, open the products table and allow image upload inline. (Perhaps removing the permission of adding products directly so they will only edit existing products.)

But this is kind of janky, don't you think?

Ideas welcome.

like image 896
joedevon Avatar asked Nov 05 '22 20:11

joedevon


1 Answers

I would do it like this.

One model holds the top-level product info. Then have a related table for the style/colour information, call it ProductDetail - it would have foreign keys to Product, Style, Colour and Fabric, plus an image and probably an SKU field.

Then your import form can use the FK from ProductDetail to Product to show the details inline to the main product. Each row, then, has a dropdown for style, colour and fabric, and each of these fields would use Django's FK widget to either select from existing options or invoke a popup to add a new one. Then the imagefield is right next to the options for each row, so is specific for that individual combination.

Does that work?

like image 97
Daniel Roseman Avatar answered Nov 15 '22 05:11

Daniel Roseman