question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Declaring a manager with a custom queryset does not work.

See original GitHub issue

When following the SafeDelete documentation, it seems declaring a manager with a custom queryset should be done like this: objects = SafeDeleteManager(MyCustomQuerySet)

Following this:

  • The manager works as expected
  • But the methods of my custom queryset are not visible! I got errors like: AttributeError: 'SafeDeleteManager' object has no attribute 'my_custom_method_from_my_custom_queryset' when I try to access it.

I found a workaround using from_queryset method with safedelete? objects = SafeDeleteManager.from_queryset(MyCustomQuerySet)()

This way, everything seems to work, but I’m worry I’m missing something. Could you please tell me if I did something wrong with the official method? Otherwise, the documentation should be updated.

Note : I’m using Django 1.11 Thanks a lot for this very useful lib by the way.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Gagarocommented, Dec 31, 2019

You are overriding the get_safedelete method which set the _safedelete_visibility attribute. See https://github.com/makinacorpus/django-safedelete/blob/master/safedelete/managers.py#L57-L62.

Set _queryset_class on your manager to MyQuerySet and remove your get_queryset method.

1reaction
Gagarocommented, Apr 24, 2018

I think your solution should be the correct one. I see that we overwrite _queryset_class in our __init__ method, but it is always better to keep the same api as Django.

I don’t remember why it was done that way, we should try to remove the __init__ method and change the documentation accordingly if this works as intended.

Thanks for the report 👍 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using custom Manager & QuerySet does not work with related ...
After that in your class AttendanceLog(Model) you need to declare : objects = AttendanceLogManager(). I found this link very helpful.
Read more >
Managers - Django documentation
There are two reasons you might want to customize a Manager : to add extra Manager methods, and/or to modify the initial QuerySet...
Read more >
Managers - Django 1.4 documentation
A custom Manager method can return anything you want. It doesn't have to return a QuerySet . For example, this custom Manager offers ......
Read more >
Better Models Through Custom Managers and QuerySets
... to get common queries chain-able, and slimmer. This video goes over custom model managers and custom querysets so you can write better...
Read more >
The data layer | Google Tag Manager for Web
The data layer is an object used by Google Tag Manager and gtag.js to pass information to tags. Events or variables can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found