Database Layouts

Hi,

I’m new to Django and relational tables in general.

OPTION 1

If I have a table with following fields

Name, Address, No Channels

Address can be between 1 and 512,

No channels between 1 and 8.

When the above table is submitted, I would like to populate a second table with the following,

Channel No Channel Details

Where the channel numbers would contain the no of channels submitted in the first model with the address offset. Channel details would be generic text to be updated by the user later.

For example, if the following was submitted to table 1.

Dimmer1 200 4

The second table is populated with

200 xxx

201 xxx

202 xxx

203 xxx

Subsequent submissions should append to table 2 in a similar way.

OPTION 2

Or would this be better as a single table,

Name, Address, No CH, C1 No, C1 Name, C2 No, C2 Name etc.

Use JS to hide the unused channels in a form based on address & No CH.

Using option 2, is there a “best method” to get the 8 separate fields into a single list?

Thanks

Shaun

Option 1 is the proper (“normalized”) way of doing this.

In addition to the data that needs to exist in the second table, that second table would also have a foreign key to the first table to establish the One-To-Many relationship between them.

Option 1 is normalization of database and it has one to many relation, it avoids Redundency.

As for 2nd option you will have to deal with complex Queries and it is not scable and lot of null fields will be there. Hiding with js you can hide unused field with ui but it does not solve database architecture. I would suggest 1st option.