Comments (14)
That's correct. As the documentation (http://packages.python.org/django-taggit/api.html#similar-objects) says, this method returns a list, not a queryset. I don't think there's anything we can do about this.
from django-taggit.
I haven't thought of anything, so I'm closing this.
from django-taggit.
sorry for being late to explain my feature request.
The current implementation requires me to call similar_objects once to get a list of all objects which look the same according to their tags. When I want to apply further filter on that result set, I need to get the IDs of all returned objects first and then do a second query with my filters and the ID list.
I owe you a beer if you could improve the similar_objects method to accept a filter queryset that applies on the queryset to retrieve similar objects ;D.
from django-taggit.
I've reopened this to think about it some more.
from django-taggit.
Bump
I really don't want to hurry you since a good job needs the time it requires but I need that feature soon and I believe you can do the job much better here then me.
from django-taggit.
I have a branch of Taggit in which I have implemented what seems to be a simple fix for this problem.
Here is how my similar_objects
method looks:
def similar_objects(self, num=None, **filters):
lookup_kwargs = self._lookup_kwargs()
lookup_keys = sorted(lookup_kwargs)
qs = self.through.objects.values(*lookup_kwargs.keys())
qs = qs.annotate(n=models.Count('pk'))
qs = qs.exclude(**lookup_kwargs)
subq = self.all()
qs = qs.filter(tag__in=list(subq))
qs = qs.order_by('-n')
if filters is not None:
qs = qs.filter(**filters)
if num is not None:
qs = qs[:num]
// etc... (the rest is the same)
Now a user can easily specify both a count and any filter methods that they need when doing a similar_objects
query.
from django-taggit.
I'd love to have some extra filtering in place.
Right now I'm writing a FAQ app, and would love to have it return "similar questions". That means creating a "through table" right now, because otherwise other objects will also be returned.
from django-taggit.
+1 on this.
from django-taggit.
+1, perhaps order_by would be good too
from django-taggit.
+1
Also, the ability to retrieve only objects of a specific given model would be great!
from django-taggit.
+1
from django-taggit.
FYI, this is what I've eventually written back then: https://github.com/django-fluent/django-fluent-utils/blob/master/fluent_utils/softdeps/taggit.py#L73 this code could clearly be optimized, but it could be a good starting point.
from django-taggit.
#709 is a dupe of this issue
from django-taggit.
looking at this now (after many extra years), I think it might be possible for us to solve this. Django's ORM has made many strides, though the query itself might end up being extra gnarly
from django-taggit.
Related Issues (20)
- Test suite fails if unidecode is installed
- Excluding tags in Model Managers causes failures HOT 1
- Wish to have more detail in serializer, looking for tags should be nested with all the items HOT 2
- `tag_kwargs` are not taken into account when `TAGGIT_CASE_INSENSITIVE` is `True`
- TaggedItemBase related_name not filling in %(app_label)s_%(class)s_items since Django 4.2 LTS? HOT 6
- Add support for initialising tags via a list on object creation HOT 1
- Add support for new async api HOT 2
- Getting this error while running tests: 'index_together' is deprecated. Use 'Meta.indexes' in 'taggit.TaggedItem' instead. HOT 5
- tag entered in Cyrillic be displayed in Latin
- Tag Ordering Inconsistent HOT 4
- Tags longer than 100 chars raise 500 error HOT 15
- Django Taggit 5.0 is not compatible with Django <4.1 HOT 4
- RTD builds are broken HOT 1
- Multiple queries when adding tags HOT 3
- Reverse query name for 'XXX' clashes
- New 5.0.0 migrations fails: Found wrong number (0) of indexes HOT 3
- DRF - Incorrectly processed Tag input string HOT 2
- Cannot query using tags__name__in HOT 1
- Ticket objects need to have a primary key value before you can access their tags HOT 1
- Add Django 5.0 Support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-taggit.