0

抽象モデルに created_by フィールドと modified_by フィールドを作成します。Django バージョン: 1.4.3
Python バージョン: 2.7.3
ドキュメントに従って、抽象クラスを作成しました。

# 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
south - OK
runserver - OK

SQLite Manager でテーブルを確認すると、すべて問題ないように見えます。

管理サイトにログインしてテーブルを開くと、次のようになります。

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では大丈夫ですか?

編集:
はい、これは、管理パネルで任意のモデルのリスト ビューを開くと発生しました。
すべての list_displays から created_by と modified_by を削除しました。SQLite を使用するローカル マシンでも、Postgres を使用するサーバーでも役に立たなかった

すべてのテストは正しいです。

4

3 に答える 3

1

created_by と modified_by だけでなく、list_display からすべてのリレーションを削除する必要がありました。次に、例のようにビューに新しい列を作成します。

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'
于 2013-04-30T08:48:07.607 に答える
1

SQLiteのドキュメントによると、最大 64 個の結合に制限されています。

これが発生したとき、あなたはどの管理ビューを使用していますか? リストビューだと思いますか?

を使用して管理者に表示するフィールドを手動で指定することにより、リスト表示の 2 つの外部キー フィールドを無視できます。

list_display

于 2013-04-29T20:36:38.587 に答える
1

実際、ドキュメントが指摘しているように、Sqlite3は結合の数を64テーブルに制限しています。ほとんどの場合、他のデータベース エンジンを使用しても問題ありません。

于 2013-04-29T20:35:20.443 に答える