Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting static block also deletes products #212

Open
emilian opened this issue Dec 3, 2017 · 4 comments
Open

Deleting static block also deletes products #212

emilian opened this issue Dec 3, 2017 · 4 comments

Comments

@emilian
Copy link

emilian commented Dec 3, 2017

I had a big surprise today where deleting a static block also removed the products referencing the block. To stop this the lfs/catalog/models.py file should use on_delete=models.SET_NULL for the static_block foreign key. Like this:

static_block = models.ForeignKey("StaticBlock", on_delete=models.SET_NULL, verbose_name=_(u"Static block"), blank=True, null=True, related_name="products")

That should solve the problem for the products.

pigletto added a commit that referenced this issue Dec 3, 2017
This was referenced Dec 3, 2017
@emilian
Copy link
Author

emilian commented Dec 4, 2017

Looks good.

Is it possible to do the same for categories as well?

@emilian
Copy link
Author

emilian commented Dec 4, 2017

Right now the code is manually setting the static_block field to null for categories.

Here's the relevant code:

https://github.com/diefenbach/django-lfs/blob/master/lfs/manage/static_blocks/views.py#L247

That code could be removed with the same setting for the category model as well.

@pigletto
Copy link
Collaborator

pigletto commented Dec 4, 2017

I've updated the Pull Request. Seems that code for setting None was created before on_delete was added to Django.

@emilian
Copy link
Author

emilian commented Dec 4, 2017

That was fast. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants