开发者

Django ManyToMany returning error "MultipleObjectsReturned while rendering"

New to Django so apologies if this is head-smackingly obvious.

My app's models include a Band class, a Release class for music CDs, and a Press class for reviews of these CDs. The Press class looks like this:

class Press(models.Model):
    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name_plural = "Press"

    band = models.ManyToManyField('Band', null=True, blank=True)
    release = models.ManyToManyField('Release', null=True, blank=True)    
    title = models.CharField(max_length=500)
    article = models.TextField(blank=True)
    url = models.URLField(max_length=100, blank=True)
    screenshot = models.ImageField(upload_to='press/', blank=True)

I recently changed this (before, the band/release were ForeignKeys) and resynced my database. Now I get this error anytime I try to list my Releases:

"Caught MultipleObjectsReturned while rendering: get() returned more than one Press -- it returned 4! Lookup parameters were {}"

The code causing this is:

def release_list(request):
    r = Release.objects.order_by('-release_date')[:5]
    return {'release_list' : r}

Am I doing something obviously wrong here? I'm not trying to access any of the Press fields so I'm not sure why it's try开发者_Go百科ing to get them.

Full traceback here.

Thanks, Matt


Never mind - inside my views I was referring to a Press var that no longer existed. Annoying that Django didn't point to that specific line of code, but all fixed!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜