[Answered ]-Django โ€“ What is the best way to set up a model with lots of similar fields?

2๐Ÿ‘

If you ever find yourself in a situation where you are adding more than one field of the same type to a database table, you need to normalize the database. This involves setting up a separate table with entries for each question and then link them to whatever table you are trying to add multiple entries into. More on database normalization here:

http://en.wikipedia.org/wiki/Database_normalization

To implement in Django, use the following fields in your model depending on the type of link you need.

One to many: https://docs.djangoproject.com/en/dev/ref/models/fields/#foreignkey

Many to many: https://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield

๐Ÿ‘คDaniel Kuntz

Leave a comment