Django

Code

Ticket #4464 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

Chaining filters on ManyToManyFields broken?

Reported by: ml_django25@joebutton.co.uk Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: manytomany, manytomanyfield, qs-rf-fixed
Cc: b-django@codecontractors.net Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The last part of this fails (with MySql? 5):

from django.db import models

class Category(models.Model):
    name=models.CharField(maxlength=40)

class Thing(models.Model):
    """
    >>> cat1 = Category.objects.create(name="cat2")
    >>> cat1.save()
    >>> cat2 = Category.objects.create(name="cat2")
    >>> cat2.save()
    >>> my_thing = Thing.objects.create(name="My thing")
    >>> my_thing.save()
    >>> my_thing.categories = [cat1, cat2]
    >>> Thing.objects.filter(categories=cat1)
    [<Thing: My thing>]
    >>> Thing.objects.filter(categories=cat2)
    [<Thing: My thing>]
    >>> Thing.objects.filter(categories=cat1).filter(categories=cat2)
    [<Thing: My thing>]
    """
    name=models.CharField(maxlength=40)
    categories = models.ManyToManyField(Category)
    def __str__(self):
        return self.name

Am I right in thinking that ought to pass?

Attachments

Change History

07/16/07 08:40:04 changed by mtredinnick

  • owner changed from adrian to mtredinnick.
  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

This is a dupe of something (I thought), but I can't find. It should work. I'm working on it.

07/23/07 12:39:31 changed by anonymous

  • cc set to b-django@codecontractors.net.

09/13/07 16:42:38 changed by mtredinnick

  • keywords changed from manytomany, manytomanyfield to manytomany, manytomanyfield, qs-rf-fixed.

04/26/08 21:50:16 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658


Add/Change #4464 (Chaining filters on ManyToManyFields broken?)




Change Properties
Action