2017-12-19 11 views
0

처음으로 Peewee Python ORM (Playhouse 모듈이있는 PostgreSQL)을 사용하고 있는데 다음과 같이하고 싶습니다. class Person(BaseModel): followers = ManyToManyField(rel_model=Person, related_name='following') Person을 정의하지 않았기 때문에 NameError가 발생합니다. 논의. ManyToManyField를 사용하여 원하는 작업을 수행 할 수있는 깨끗한 방법이 있습니까? 아니면 ManyToManyField 기능이없는 것처럼 별도의 접합 테이블을 만들어야합니까?peewee에서 자기 참조 다 대다 필드를 만드는 방법은 무엇입니까?

답변

1

당신은 이런 식으로 뭔가를 할 것입니다 :

class Person(Model): 
    name = TextField() 

class Follower(Model): 
    from_person = ForeignKeyField(Person, related_name='followers') 
    to_person = ForeignKeyField(Person, related_name='followed_by')