Opened 16 years ago

Closed 14 years ago

#8161 closed Bug (invalid)

ManyToManyField with relation to self not saved in admin when using inheritance

Reported by: Mathijs de Bruin Owned by: Jonas Obrist
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: newforms newforms-admin admin inheritance manytomany self
Cc: drbob@…, madhusudancs@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the following example code, the 'links' field does not get saved in the admin for ChildModel:

class ParentModel(models.Model):
    slug = models.SlugField()

    # For some reason, changes do not get saved (anymore)
    links = models.ManyToManyField('self', related_name='links', null=True, blank=True)
                    
    def __unicode__(self):
        return self.slug
        
class ChildModel(ParentModel):
    text = models.TextField()

The admin is registred simply by using:
admin.site.register(ChildModel)

It seems to me this is a bug in either the newforms Admin or newforms.

Change History (11)

comment:1 by Mathijs de Bruin <drbob@…>, 16 years ago

Cc: drbob@… added

comment:2 by sebastian.hillig, 16 years ago

milestone: 1.0
Owner: changed from nobody to sebastian.hillig
Status: newassigned

A specific ChildModel seems only to save itself as a link, refuses to save every other child.

comment:3 by sebastian.hillig, 16 years ago

Triage Stage: UnreviewedAccepted

in reply to:  3 comment:4 by sebastian.hillig, 16 years ago

Owner: changed from sebastian.hillig to nobody
Status: assignednew

Fat fingers i guess. Only wanted to accept that one.

comment:5 by James Bennett, 16 years ago

milestone: 1.0post-1.0

Lack of activity/patch here, and the fact that it's a relatively uncommon case suggests this probably can be handled post-1.0.

comment:6 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:7 by madhusudancs@…, 16 years ago

Component: Core frameworkDatabase layer (models, ORM)

With the same code piece I just inserted test1 test2 test3 as slug field values for ParentModel and testc1 testc2 and testc3 for ChildModel and linked testc2 to testc1 and testc3 to testc2

The bug is not just in the admin, it happens on the interactive interpreter too. This is the small piece of test code on the interpreter.

from dummy.testapp.models import ChildModel, ParentModel
ChildModel.objects.all()

[<ChildModel: testc1>, <ChildModel: testc2>, <ChildModel: testc3>]

ParentModel.objects.all()

[<ParentModel: test1>, <ParentModel: tes2>, <ParentModel: test3>, <ParentModel: testc1>, <ParentModel: testc2>, <ParentModel: testc3>]

c2 = ChildModel.objects.get(slug='testc2')
c2.links

<django.db.models.fields.related.ManyRelatedManager object at 0x99c490c>

c2.links.all()

[]

c1 = ChildModel.objects.get(slug='testc1')
c1.links.all()

[<ParentModel: testc2>, <ParentModel: testc3>]

c3 = ChildModel.objects.get(slug='testc3')
c3.links.all()

[]

So I suppose this bug is not just in admin Interface but in the ORM itself. So I change the component. Can some one help me track this bug and fix it? As in how to go about? Where to look for the code?

comment:8 by madhusudancs@…, 16 years ago

Cc: madhusudancs@… added
Version: 1.0-alphaSVN

comment:9 by Luke Plant, 14 years ago

Severity: Normal
Type: Bug

comment:10 by Jonas Obrist, 14 years ago

Easy pickings: unset
Owner: changed from nobody to Jonas Obrist
UI/UX: unset

comment:11 by Jonas Obrist, 14 years ago

Resolution: invalid
Status: newclosed

can't reproduce, ran both admin and the python code.

Note: See TracTickets for help on using tickets.
Back to Top