Declaring a manager with a custom queryset does not work.
See original GitHub issueWhen 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:
- Created 5 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 toMyQuerySet
and remove yourget_queryset
method.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 👍 .