Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#11750 closed (worksforme)

ManyToMany field does not respect Proxy models

Reported by: mxposed Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: manytomany proxy
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi

I have a proxy model above django.contrib.auth.models.User
and i have a ManyToMany field referencing to django.contrib.auth.models.User

When i try to add an instance of my proxy class to the field i get the TypeError: 'user' instance expected

class MyUser(User):
     class Meta:ΒΆ
         proxy = True

class Item(models.Model):
    owners = models.ManyToManyField(User)

Item.objects.get(fk=1).owners.add(MyUser.objects.get(fk=1))

Change History (2)

comment:1 by Johannes Dollinger, 15 years ago

Resolution: β†’ worksforme
Status: new β†’ closed

I cannot reproduce this with r11638.

import unittest
from django.db import models
from django.contrib.auth.models import User

class A(User): 
    class Meta:
        proxy=True
        
class B(models.Model):
    a_set = models.ManyToManyField(A)
    
class T11750(unittest.TestCase):
    def test_11750(self):        
        user = User.objects.create(username="foo")
        a = A.objects.get()
        b = B.objects.create()
        b.a_set.add(a)

comment:2 by Johannes Dollinger, 15 years ago

There's an error in my test: a_set should point to User. But still not reproducible.

import unittest
from django.db import models
from django.contrib.auth.models import User

class A(User): 
    class Meta:
        proxy=True
        
class B(models.Model):
    a_set = models.ManyToManyField(User)
    
class T11750(unittest.TestCase):
    def test_11750(self):        
        user = User.objects.create(username="foo")
        a = A.objects.get()
        b = B.objects.create()
        b.a_set.add(a)
        
Note: See TracTickets for help on using tickets.
Back to Top