2013-04-29 106 views
0

我在我的抽象模型中创建created_by和modified_by字段。 Django的版本:1.4.3
Python版本:2.7.3
与文档根据我创建了抽象类:Django created_by和modifed_by管理网站问题

# base.py 
class MyModel(models.Model): 
    created_by = models.ForeignKey('userdata.Profile', 
            related_name= 
            '%(app_label)s_%(class)s_created_by', 
            default=1) 
    modified_by = models.ForeignKey('userdata.Profile', 
            related_name= 
            '%(app_label)s_%(class)s_modified_by', 
            default=1) 
    class Meta: 
     abstract = True 

我继承我的约50款全系车型这一模式。

执行syncdb - OK
南 - OK
的runserver - OK

我期待通过SQLite的经理我的表,一切都看起来很好。

我登录到管理界面,打开任何我的表,我也得到:

Traceback: 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\core\handlers\base.py" in get_response 
    111.       response = callback(request, *callback_args, **callback_kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\contrib\admin\options.py" in wrapper 
    366.     return self.admin_site.admin_view(view)(*args, **kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\utils\decorators.py" in _wrapped_view 
    91.      response = view_func(request, *args, **kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\views\decorators\cache.py" in _wrapped_view_func 
    89.   response = view_func(request, *args, **kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\contrib\admin\sites.py" in inner 
    196.    return view(request, *args, **kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\utils\decorators.py" in _wrapper 
    25.    return bound_func(*args, **kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\utils\decorators.py" in _wrapped_view 
    91.      response = view_func(request, *args, **kwargs) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\utils\decorators.py" in bound_func 
    21.     return func(self, *args2, **kwargs2) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\contrib\admin\options.py" in changelist_view 
    1233.    'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\db\models\query.py" in __len__ 
    85.     self._result_cache = list(self.iterator()) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\db\models\query.py" in iterator 
    291.   for row in compiler.results_iter(): 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\db\models\sql\compiler.py" in results_iter 
    763.   for rows in self.execute_sql(MULTI): 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\db\models\sql\compiler.py" in execute_sql 
    818.   cursor.execute(sql, params) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\db\backends\util.py" in execute 
    40.    return self.cursor.execute(sql, params) 
File "I:\xxx\virtualenvs\fff-2\lib\site-packages\django-1.4.3-py2.7.egg\django\db\backends\sqlite3\base.py" in execute 
    344.    return Database.Cursor.execute(self, query, params) 
Exception Type: DatabaseError at /admin/userdata/address/ 
Exception Value: at most 64 tables in a join 

我的问题是:你能看到在这个例子中的任何错误?
我的问题2:SQLite限于64个连接吗?在Postgres上它会没事的?

EDITE:
是的,当我打开列表查看管理面板中的任何模型时发生这种情况。
我从所有list_displays中删除了created_by和modified_by。没有帮助本地mashine与SQLite和服务器与Postgres

所有的测试都是正确的。

回答

1

我不得不删除每一个对应关系从list_display不仅CREATED_BY和modified_by在管理中显示忽略列表显示在你的两个外键的字段。然后创建新的colummns在视图中,如在示例中:

class MyModelAdmin(admin.ModelAdmin): 
    list_display = ('level', 'description', '_parent', '_created_by', 
        '_modified_by') 

    def _parent(self, obj): 
     return "%s" % obj.parent 

    _parent.short_description = 'Parent' 

    def _created_by(self, obj): 
     return "%s" % obj.created_by 

    _created_by.short_description = 'Created By' 

    def _modified_by(self, obj): 
     return "%s" % obj.modfied_by 

    _modified_by.short_description = 'Modified By' 
+0

所以你解决了它。太棒了,那是一个非常奇怪的错误:) – 2013-04-30 12:54:20

1

事实上,Sqlite3将连接数限制为64个表,因为doc指出。这很可能与其他数据库引擎,你会没事的。

+0

+1为SQLite的答案,但仍然无法正常工作。 – 2013-04-29 22:07:57

1

SQLite documentation表示它们被限制为最多64个连接。

当发生这种情况时,您有哪些管理员视图?我假设它是列表视图?

你可以手动指定哪些字段使用

list_display

+0

我更新我的问题。 – 2013-04-29 21:40:49

+0

为SQLite的答案,但仍然无法正常工作。 – 2013-04-29 22:06:50