#25537: Model objects not showing after changing M2M to ForeinKey
-------------------------------+--------------------------------------
Reporter: yaniv14 | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by yaniv14):
First I had this in my models.py
{{{
#!python
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
--
Ticket URL: <https://code.djangoproject.com/ticket/25537#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.ca76c36fdb28ec721a5cd687729de2e4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.