首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MemoryError .没有提供异常消息

MemoryError .没有提供异常消息
EN

Stack Overflow用户
提问于 2016-01-03 13:18:13
回答 2查看 1.4K关注 0票数 1

我有一个非常简单的ManyToMany关系:

代码语言:javascript
复制
@python_2_unicode_compatible
class Mot(BaseModel):
    groupes_categories = models.ManyToManyField(GroupeCategories, blank=True,
                                                through='MotGroupeCategories',
                                                symmetrical=False,
                                                related_name='mot')
    texte = models.CharField(max_length=150)

    def __str__(self):
        return _(u'{}').format(self.texte)


@python_2_unicode_compatible
class GroupeCategories(models.Model):
    description = models.CharField(max_length=150)
    exemple = models.CharField(max_length=150, blank=True, default=None,
                               null=True)

    def __str__(self):
        return _(u'{0}{1}').format(
            self.description,
            u' ({0})'.format(self.exemple) if self.exemple else u''
        )


@python_2_unicode_compatible
class MotGroupeCategories(models.Model):
    mot = models.ForeignKey(Mot, blank=False)
    groupe_categories = models.ForeignKey(GroupeCategories, blank=False)

    def __str__(self):
        return u'{} - {}'.format(self.mot.texte,
                                 self.groupe_categories.description)

我已经做了很多次了,一切都很好,除非我想通过管理MotGroupeCategories进行编辑

代码语言:javascript
复制
class MotGroupeCategoriesAdmin(admin.ModelAdmin):

    def mot_texte(self, obj):
        return obj.mot.texte
    mot_texte.allow_tags = True
    mot_texte.short_description = _(u'I.')

    fields = ('mot', 'groupe_categories')
    list_display = ('groupe_categories', 'mot_texte', 'id')
    list_display_links = list_display
    search_fields = ['description']


admin.site.register(MotGroupeCategories, MotGroupeCategoriesAdmin)

除了我想编辑一个MotGroupeCategories之外,一切都很好:所有的管理员urls都是这样的:

代码语言:javascript
复制
/admin/main/motgroupecategories/[id]/

结果

代码语言:javascript
复制
MemoryError at /admin/main/motgroupecategories/12060915/
No exception message supplied
Request Method: GET
Request URL:        /admin/main/motgroupecategories/[id]/
Django Version: 1.8.7
Exception Type: MemoryError
Exception Location: C:\Python27\lib\site-packages\django\forms\widgets.py
    in render_options, line 547

这是我第一次遇到这样一个奇怪的问题,而且在堆叠溢出方面没有这样的问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-03 22:50:42

有关raw_id_fields,请参阅字段

要编写自定义的延迟加载ModelChoiceField,请参阅Django自定义小部件

票数 1
EN

Stack Overflow用户

发布于 2016-04-05 18:33:44

我知道这不是问题的答案,但它可以帮助澄清哪种情况可以造成这一错误,至少它会对我有所帮助。

我在使用django rest框架时获得了MemoryError,因为我有一个外键,其中有一个包含2000000+项的表,web可浏览API希望将所有条目添加到下拉列表中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34576948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档