Git Product home page Git Product logo

Comments (14)

alex avatar alex commented on July 17, 2024

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.

alex avatar alex commented on July 17, 2024

I haven't thought of anything, so I'm closing this.

from django-taggit.

askowronek avatar askowronek commented on July 17, 2024

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.

alex avatar alex commented on July 17, 2024

I've reopened this to think about it some more.

from django-taggit.

askowronek avatar askowronek commented on July 17, 2024

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.

joshmaker avatar joshmaker commented on July 17, 2024

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.

vdboor avatar vdboor commented on July 17, 2024

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.

melinath avatar melinath commented on July 17, 2024

+1 on this.

from django-taggit.

b-jam avatar b-jam commented on July 17, 2024

+1, perhaps order_by would be good too

from django-taggit.

avorio avatar avorio commented on July 17, 2024

+1

Also, the ability to retrieve only objects of a specific given model would be great!

from django-taggit.

legshort avatar legshort commented on July 17, 2024

+1

from django-taggit.

vdboor avatar vdboor commented on July 17, 2024

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.

rtpg avatar rtpg commented on July 17, 2024

#709 is a dupe of this issue

from django-taggit.

rtpg avatar rtpg commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.