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

Problem deleting item #42

Open
morenoh149 opened this issue Jan 12, 2017 · 5 comments
Open

Problem deleting item #42

morenoh149 opened this issue Jan 12, 2017 · 5 comments

Comments

@morenoh149
Copy link

morenoh149 commented Jan 12, 2017

I'm writing a test and deleting items in the reverse order from which they were created.

Say Model B requires a relationship to Model A.
Create Model a
Create Model b where b.A = a
Delete Model b.
When deleting Model a I get

/project/env/project/lib/python2.7/site-packages/softdelete/models.py in delete
                self._do_delete(cs, x) ...
▶ Local vars
/project/env/project/lib/python2.7/site-packages/softdelete/models.py in _do_delete
                    getattr(self, rel).__class__.objects.all().delete() 

type object 'RelatedManager' has no attribute 'objects'

What's going on?

@morenoh149
Copy link
Author

The RelatedManager class does not have .objects.

We either want to use related_set
Or I'm somehow using this plugin wrong

@morenoh149
Copy link
Author

the line number seems to map to https://github.com/scoursen/django-softdelete/blob/master/softdelete/models.py#L185
my full error

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/harrymoreno/foobar/management/commands/foobar.py", line 27, in handle
    i.delete()
  File "/usr/local/lib/python2.7/site-packages/softdelete/models.py", line 226, in delete
    self._do_delete(cs, x)
  File "/usr/local/lib/python2.7/site-packages/softdelete/models.py", line 179, in _do_delete
    getattr(self, rel).__class__.objects.all().delete()
AttributeError: type object 'RelatedManager' has no attribute 'objects'

@ssidorenko
Copy link

@morenoh149 did you ever find a solution ?

@morenoh149
Copy link
Author

@ssidorenko I don't think so. These days I just add a deleted_at timestamp and use orm filters in the views.

@PratikBodawala
Copy link
Contributor

I have fixed this issue in #86, let me know if this works for you.

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

3 participants