I have 2 models named: PaymentMode and Store as:
PaymentMode Model: (id will be auto generated by django)
id = model.IntegerField(primarykey)
name = model.CharField("eg: cash, debit, credit")
Store Model: (id will be auto generated by django)
id = model.IntegerField(primarykey)
payment_mode = model.ForeignKey(Paymentmode, on_delete=model.cascade)
mode_credit_value = model.IntegerField(default=0)
name = model.CharField()
... some other fields
So what i want is whenever a store is created, all payment modes inherits automatically, inherit all foreign keys, this will make multiple rows in store table as: (if store with id 1 is added, 3 rows for 1, similarly for other)
store_id | payment_mode | name
------------------------------
1 1 abcd
1 2 abcd
1 3 abcd
... similarly if store id 2 is passed, all master are inherited
2 1 xyz
2 2 xyz
2 3 xyz
i looked at various stackoverflow question, probably this might be duplicate, but those all overrides save function and make only one inherited object like:
Stackoverflow question
so the question is will save function override approach in above question inherit all foreign keys? or will it make only one?
Obviously payment modes will be created first. Also in future if a payment mode is added, is it possible to add new payment mode to all pre-existing stores automatically?
Probably my approach of creating model is wrong.