[Answer]-Dynamic table name and dynamic field for django 1.8

1👍

Not sure if I fully understand your problem, but it seems to me that you should reconsider your database structure. I’m not very experienced but adding tables to db on a regular basis on the fly is not good.

CategoryStore model will have table names as category_store_1, category_store_2, etc.

Keeping in mind that in django 1 model <=> 1 db table, try this approach: one table called CategoryStore which holds data from all your stores and another table called CategoryStoreType with the following structures:

CategoryStore has all the fields you need plus a type field which is a foreign key to CategoryStoreType. CategoryStoreType contains a short description of each store type, e.g. a tuple ('id', 'type name'). This way when you need a new field for one store type you simply add another field to CategoryStore, which holds data of all your store types. (Again, as for tables, adding fields on the fly is not that good, imho.)

👤Sirion

Leave a comment