Opened 12 years ago

Closed 9 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: master
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


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:

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

Change History (11)

comment:1 Changed 12 years ago by Mathijs de Bruin <drbob@…>

Cc: drbob@… added

comment:2 Changed 12 years ago by sebastian.hillig

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 Changed 12 years ago by sebastian.hillig

Triage Stage: UnreviewedAccepted

comment:4 in reply to:  3 Changed 12 years ago by sebastian.hillig

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

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

comment:5 Changed 12 years ago by James Bennett

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 Changed 12 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:7 Changed 12 years ago by madhusudancs@…

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: testc1>, <ChildModel: testc2>, <ChildModel: testc3>]


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

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

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



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

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

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


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 Changed 12 years ago by madhusudancs@…

Cc: madhusudancs@… added
Version: 1.0-alphaSVN

comment:9 Changed 9 years ago by Luke Plant

Severity: Normal
Type: Bug

comment:10 Changed 9 years ago by Jonas Obrist

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

comment:11 Changed 9 years ago by Jonas Obrist

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