Opened 9 years ago

Closed 9 years ago

#25537 closed Bug (worksforme)

Model objects not showing on admin changelist page after changing M2M to ForeignKey

Reported by: Yaniv Mirel Owned by: nobody
Component: contrib.admin Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've changed on a model one of the fields from Many2Many to nullable ForeignKey.
After the migration when I enter the admin panel to the mentioned model I don't see any of the existing objects from that model but I do see in paginator the correct count amount.

Attachments (1)

Select Menu item to change - Django site admin.png (47.3 KB ) - added by Yaniv Mirel 9 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Tim Graham, 9 years ago

Could you please add more details such as a sample project so we can reproduce the issue?

comment:2 by Yaniv Mirel, 9 years ago

First I had this in my models.py

class MenuTime(models.Model):
    title = models.CharField(_('Title'), max_length=200)
    order = models.PositiveSmallIntegerField(_('Order'), default=1)

    class Meta:
        verbose_name = _('Menu time')
        verbose_name_plural = _('Menu times')
        ordering = ['order', ]

    def __unicode__(self):
        return self.title


class MenuGroup(models.Model):
    title = models.CharField(_('Title'), max_length=200)

    class Meta:
        verbose_name = _('Menu group')
        verbose_name_plural = _('Menu groups')

    def __unicode__(self):
        return self.title


class HealthQuestionnaire(models.Model):
    title = models.CharField(_('Name'), max_length=200)

    class Meta:
        verbose_name = _('Health questionnaire')
        verbose_name_plural = _('Health questionnaires')

    def __unicode__(self):
        return self.title


class MenuItem(models.Model):
    name = models.CharField(_('Name'), max_length=200)
    time = models.ManyToManyField(MenuTime, related_name='menu_items')
    group = models.ForeignKey(MenuGroup, related_name='menu_items')
    male = models.BooleanField(_('For male?'), default=True)
    female = models.BooleanField(_('For female?'), default=True)
    image = ImageField(upload_to='menus', verbose_name=_("Menu image"), blank=True, null=True)
    not_allowed = models.ManyToManyField(HealthQuestionnaire, verbose_name=_("Not allowed with"),
                                         related_name='menu_items', blank=True)

    class Meta:
        verbose_name = _('Menu item')
        verbose_name_plural = _('Menu items')
        ordering = ['-name']

    def __unicode__(self):
        return self.name

    def admin_thumbnail(self):
        return u'<img src="%s" width="120" height="auto" />' % self.image.url if self.image else None

    admin_thumbnail.short_description = _('Thumbnail')
    admin_thumbnail.allow_tags = True

    def not_allowed_list(self):
        return ", ".join([x.title for x in self.not_allowed.all()])

    not_allowed_list.short_description = _('Not allowed list') 

And I had 11 MenuItem objects created from django admin, later I decided to change the relation of time field from M2M to ForeignKey -> "time = models.ForeignKey(MenuTime, related_name='menu_items', null=True)"

I ran manage.py makemigration and migrate and then I've started to notice the issue.
All 11 objects are still accessible and the bug I have is only in the django admin list display.
If i am adding to the url the object ID (127.0.0.1:8000/admin14/core/menuitem/2/) I am able to see the correct object in the admin panel.

Hope it helps to reproduce the bug

comment:3 by Tim Graham, 9 years ago

I can't reproduce the issue. Maybe the issue is caused by certain data you've created. Can you be more specific with the minimal steps to reproduce it or provide a SQLite database that demonstrates the issue?

comment:4 by Tim Graham, 9 years ago

Summary: Model objects not showing after changing M2M to ForeinKeyModel objects not showing on admin changelist page after changing M2M to ForeignKey

comment:5 by Yaniv Mirel, 9 years ago

I already wrote the steps that I did.
I cannot attach the sqlite db file because I already modified that file and it will not show the bug any more.
This is just a project in early stages of development.
I will try to reproduce this bug again in the future.
If you want to close the ticket or leave it open for now its up to you.

Thank you

comment:6 by Collin Anderson, 9 years ago

Usually if the rows don't show up that means there's an error that's getting silenced somewhere. Scale back (or disable) your list_display and try to figure out which column is causing the error.

comment:7 by Tim Graham, 9 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top