Issue #2 resolved

OwnerMixinManager parameters causes ManyToMany mappings to fail

Jason Slater
created an issue

I am new to Python and Django, so please forgive me if I'm wrong here.

this bug fully describes what I've encountered with models which use the SingleOwnerMixin or MultipleOwnerMixin classes, when trying to access related records. it doesn't appear to have been resolved.

My workaround is to create two manager classes, basically duplicating the existing manager class and modifying the init function of each to remove the extra parameter, e.g.

class SingleOwnerMixinManager(models.Manager):
    def __init__(self):
        super(SingleOwnerMixinManager, self).__init__()
        self.__owner_filter = 'owner'


class MultipleOwnerMixinManager(models.Manager):
    def __init__(self):
        super(MultipleOwnerMixinManager, self).__init__()
        self.__owner_filter = 'owners'

and then for each Mixin to use the appropriate manager, e.g.

class   SingleOwnerMixin(OwnerMixinBase):
    objects = SingleOwnerMixinManager()
class MultipleOwnerMixin(OwnerMixinBase):
    objects = MultipleOwnerMixinManager()

Comments (7)

  1. Tim Savage repo owner

    Will take a look at this issue, if the problem is related to an upstream issue in Django I am a little wary of patching on top of Django, might solve the problem now but cause more problems if my solution is different from the Django one.

  2. Jason Slater reporter

    Thanks, Tim, and thank you for sharing and maintaining your code. It has been extremely helpful to me.

    My workaround does work fine and does not involve patching Django at all. It's not exactly elegant because it involves duplicating the manager class. If I understand correctly, Django is instantiating the manager whenever related fields are accessed, in both ForeignKey and ManyToMany relationships. When it does so, Django will fail if the constructor has any additional arguments.

  3. Tim Savage repo owner

    Another note that if you use the owner_list() method when you want to fetch a list of users associated with an owned item. This will always return a list of user objects with either the SingleOwnerModel or MultipleOwnerModel. This will allow you to use the same code with either types of model.

  4. Log in to comment