Django - deleting object, keeping parent?

One way to go about this would be to first add a dummy Partner per each company awaiting deletion. After that you can update the partner_ptr of all unwanted Company instances to the appropriate dummy partner instance. Finally you can delete all the companies Of course you can use South to help do this Update Did some rudimentary testing and this works.

I am using Django 1.2.1 I have tried this, it's not possible: In 1 : Company.objects. Get(pk=7924) Out 1 : In 2: c. Partner_ptr = Partner() In 3: c.Pk In 4: c.delete() AssertionError: Company object can't be deleted because its partner_ptr_id attribute is set to None.

Setting the partner_ptr instance to a dummy one changes the company's PK and it's not the Company You have to attach a new Partner and then save the company. Then you can safely delete it So: company = Company.objects. Get(pk=7924) dummy_partner = Partner(code = "dummy", name = "dummy") company.

Partner_ptr = dummy_partner company.save() company.delete().

One way to go about this would be to first add a dummy Partner per each company awaiting deletion. After that you can update the partner_ptr of all unwanted Company instances to the appropriate dummy partner instance. Finally you can delete all the companies.

Of course you can use South to help do this. Update Did some rudimentary testing and this works. I am using Django 1.2.1.

I have tried this, it's not possible: In 1: Company.objects. Get(pk=7924) Out1: In 2: c. Partner_ptr = Partner() In 3: c.Pk In 4: c.delete() AssertionError: Company object can't be deleted because its partner_ptr_id attribute is set to None.

Setting the partner_ptr instance to a dummy one changes the company's PK and it's not the Company. You have to attach a new Partner and then save the company. Then you can safely delete it.

So: company = Company.objects. Get(pk=7924) dummy_partner = Partner(code = "dummy", name = "dummy") company. Partner_ptr = dummy_partner company.save() company.delete().

I have tried this, it's not possible: In 1: Company.objects. Get(pk=7924) Out1: In 2: c. Partner_ptr = Partner() In 3: c.Pk In 4: c.delete() AssertionError: Company object can't be deleted because its partner_ptr_id attribute is set to None.

Setting the partner_ptr instance to a dummy one changes the company's PK and it's not the Company. – Alexander Sep 14 '10 at 17:27 @Alexander: see my updated answer. You have to save the company before deleting it.

– Manoj Govindan Sep 14 '10 at 17:31 Thank you, Manoj, indeed after saving the company it worked. According to the SQL log, it deletes only the from the Company table: 2010-09-14 20:43:49 EEST LOG: statement: DELETE FROM "partners_company" WHERE "partner_ptr_id" IN (7924) 2010-09-14 20:43:49 EEST LOG: statement: DELETE FROM "partners_partner" WHERE "id" IN (NULL) – Alexander Sep 14 '10 at 17:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions