2013-04-29 4 views
0

내 추상 모델에서 created_by 및 modified_by 필드를 만듭니다. 장고 버전 : 1.4.3
파이썬 버전 : 나는 50 개 모델에 대한 나의 모델이 모델을 상속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 

: 2.7.3
는 문서에 따르면 내 추상 클래스를 만들었습니다.

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_display에서 created_by 및 modified_by를 제거했습니다. SQLite를 사용하는 로컬 mashine과 Postgres를 사용하는 서버에서 모두 도움이되지 않았습니다.

모든 테스트가 정확합니다.

답변

1
내가 list_display뿐만 아니라 CREATED_BY이 (가) 작성한와 modified_by에서 제거 매 관계에 있었다

사용하여 관리자에 표시 할 어떤 필드 지정하여 목록 표시에 당신이 개 외래 키 필드를 무시할 수 . 그런 다음 예제와 같이보기에 새로운 열을 만듭니다.

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

그래서 해결했습니다. 좋아요, 아주 이상한 오류였습니다 :) –

1

실제로 Sqlite3은 doc가 가리키는 64 테이블의 조인 수를 제한합니다. 다른 데이터베이스 엔진을 사용하면 문제가 없을 것입니다.

+0

+1은 SQLite 대답이지만 여전히 작동하지 않습니다. –

1

SQLite documentation은 최대 64 개의 조인으로 제한됩니다.

이 경우 어떤 관리자보기가 켜져 있습니까? 목록보기라고 가정하고 있습니까?

수동

list_display

+0

질문을 업데이트합니다. –

+0

+1은 SQLite 응답이지만 여전히 작동하지 않습니다. –

관련 문제