Code

Opened 6 years ago

Closed 3 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: ojii
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

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.

Attachments (0)

Change History (11)

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

  • Cc drbob@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by bastih

  • milestone set to 1.0
  • Owner changed from nobody to bastih
  • Status changed from new to assigned

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

comment:3 follow-up: Changed 6 years ago by bastih

  • Triage Stage changed from Unreviewed to Accepted

comment:4 in reply to: ↑ 3 Changed 6 years ago by bastih

  • Owner changed from bastih to nobody
  • Status changed from assigned to new

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

comment:5 Changed 6 years ago by ubernostrum

  • milestone changed from 1.0 to post-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 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:7 Changed 5 years ago by madhusudancs@…

  • Component changed from Core framework to Database 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 Changed 5 years ago by madhusudancs@…

  • Cc madhusudancs@… added
  • Version changed from 1.0-alpha to SVN

comment:9 Changed 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to Bug

comment:10 Changed 3 years ago by ojii

  • Easy pickings unset
  • Owner changed from nobody to ojii
  • UI/UX unset

comment:11 Changed 3 years ago by ojii

  • Resolution set to invalid
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.