티스토리 뷰

반응형

0.들어가면서

이 게시물에서는 좋아요와 팔로우기능이 MTM(manytomany)을 통해 DB로 table이 생성될 때 자동으로 생성되는 column의 naming에 대해 알아볼 생각이다. 이 부분을 보기 전에 좋아요 기능가 팔로우 기능에 대한 개념을 모른다면 아래의 링크를 타고가서 공부하고 오자.

 

https://han-py.tistory.com/160

 

https://han-py.tistory.com/161

 


결론부터 보면

좋아요 기능의 column명은 아래와 같다.

article_id user_id
   

[table] accounts_user_followers

from_user_id to_user_id
   

 


 

공식문서를 통해 ManyToMany를 살펴보면 아래와 같다.

ManyToManyField

If you don't specify an explicit through model, there is still an implicit through model class you can user to directly access the table created to hold the association.

즉, 명시적으로 through 모델을 정의하지 않더라도 자동으로 through 모델을 유추해서 만든다. 만드는 방법은 아래 2가지이다.

 

1, The following fields are generatied (보통 이렇게 생성된다.)

  • id : the primary key of the relation
  • <containing_model>_id : the id of the model that declares the ManyToManyField
  • <other_model>_id : the id of the model that the ManyToManyField points to

2. If the ManyToManyField points from and to the same model, the following fields are generated(같은 모델)

  • id : the primary key of the relation
  • from_<model>_id : the id of the instance which points at the model(i.e. the soutce instance)
  • to_<model>_id : the id of the instance to which the relationship points (i.e. the target model instance)
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함