2014-02-09 6 views
0

here과 같이 SQlAlchemy 권장 uuid() 지원 추가 기능을 사용하고 있습니다.SQLAlchemy 'module'을 호출 할 수 없음

TypeError: 'module' object is not callable 

모듈, GUID 참조 : 내 SQLAlchemy의 코드에서 사용할 때, 나는이 오류가 발생합니다. 여기

소스에서 직접 촬영 한 GUID 코드입니다 :

GUID.py 여기

from sqlalchemy.types import TypeDecorator, CHAR 
from sqlalchemy.dialects.postgresql import UUID 
import uuid 

class GUID(TypeDecorator): 
    """Platform-independent GUID type. 

    Uses Postgresql's UUID type, otherwise uses 
    CHAR(32), storing as stringified hex values. 

    """ 
    impl = CHAR 

    def load_dialect_impl(self, dialect): 
    if dialect.name == 'postgresql': 
     return dialect.type_descriptor(UUID()) 
    else: 
     return dialect.type_descriptor(CHAR(32)) 

    def process_bind_param(self, value, dialect): 
    if value is None: 
     return value 
    elif dialect.name == 'postgresql': 
     return str(value) 
    else: 
     if not isinstance(value, uuid.UUID): 
     return "%.32x" % uuid.UUID(value) 
     else: 
     # hexstring 
     return "%.32x" % value 

    def process_result_value(self, value, dialect): 
    if value is None: 
     return value 
    else: 
     return uuid.UUID(value) 

그리고 것은 호출 내 모델입니다

user.py

from app import db 
from datetime import datetime 
from app.custom_db import GUID 

class User(db.Model): 
    __tablename__ = 'users' 
    id = db.Column(GUID(), primary_key=True) 
    email = db.Column(db.String(80), unique=True) 
    name = db.Column(db.String(80)) 
    password = db.Column(db.String(80)) 
    datejoined = db.Column(db.DateTime,default = db.func.now()) 

    def __init__(self, name, email, password): 
    self.name = name 
    self.email = email 
    self.password = password 

    def __repr__(self): 
    return '<User %r>' % self.name 

이걸 만들 수없는 이유는 무엇입니까? uuid() PKey?


여기에 전체 역 추적의

Traceback (most recent call last):                                                    
    File "./run.py", line 3, in <module>                                                   
    from app import app                                                      
    File "/home/achumbley/Pile/app/__init__.py", line 23, in <module>                                           
    from models import user                                                     
    File "/home/achumbley/Pile/app/models/user.py", line 5, in <module>                                           
    class User(db.Model):                                                      
    File "/home/achumbley/Pile/app/models/user.py", line 7, in User                                            
    id = db.Column(GUID(), primary_key=True)                                                 
TypeError: 'module' object is not callable 
+0

역 추적하시기 바랍니다. –

+0

'app/custom_db.py '는 어떻게 생겼습니까? 해당 파일에서 GUID를 가져 오므로 해당 파일이 GUID를 잘못 가져오고 있습니다. –

답변

3

파일은 GUID.py, 당신은 다음, 당신이 정말 가져온 것은이다 (당신이 그것을 가지고) from app.custom_db import GUID처럼 가져 오는 경우 파일이 아니라 클래스. 수업에 참여하려면 GUID.GUID()으로 전화해야합니다.

또는,로 가져 클래스를 가져올 수 :

from app.custom_db.GUID import GUID 
+0

.. 그리고 나는 바보 같아. 오류를 찾아 주셔서 감사합니다! –

관련 문제