모델 아키텍처 방법에 의문을 제기했습니다.확장 성/성능을위한 장고 아키텍처 선택
일부 엔티티에게 투표 할 가능성을 부여하고자합니다 (이 경우에는 종이).
옵션 1 :
Link the entity as a relationship
class Vote(model.Model):
author = models.ForeignKey(User)
created = models.DateField(auto_now=True)
value = models.IntegerField(default=1)
class Paper(models.Model):
author = models.ForeignKey(User)
edition = models.ForeignKey(ConferenceEdition)
votes = models.OneToMany(Vote)
장점 :
- 그것은
- 내가 함께이 투표 엔티티를 사용할 수있는 모델 (ORM)와 함께 작동하도록 쉽게 나는이 두 가지 가능성이 함께했다 다른 사람
- 사용자가 이미 투표 한 논문을 표시하기 위해 HTML을 렌더링 할 때이 정보가 필요할 수 있습니다.
Desavantages가 :
- 나는 데이터베이스 가장 큰 두려워, 느린 그것을 얻을 수 있습니다.
옵션 2 :
클래스
class Vote(model.Model):
author = models.ForeignKey(User)
created = models.DateField(auto_now=True)
value = models.IntegerField(default=1)
entity_id = models.IntegerField()
entity_type = models.CharField(max_length=255,default='Paper')
class Paper(models.Model):
author = models.ForeignKey(User)
edition = models.ForeignKey(ConferenceEdition)
num_votes = models.IntegerField(default=0)
Avantages를 연결하지 않기 :
- 그것은 게으른 로딩 종류의, 나는 카운터를하고 난 정보를 필요로하는 경우 나는 그것을 갈 수있다.
- 그것은 빠릅니다
Desavantages을 (내 생각) :
이- 당신은 모든 새로운 표를 업데이트하는 새로운 논리에 의존해야합니다.
옵션 3 : 내가
감사를 듣고있어
!
+1 첫 번째와 세 번째 방법의 조합을 고려해야합니다. 내가 투표 할 때 ManyToManyField를 사용하는 것이 확실하지 않은 이유는 동일한 투표가 여러 개의 서류에 적용될 수 있을지 확신하지 못하기 때문입니다. 그럴 수 없다면 OneToMany로 충분할 것입니다. – astevanovic
예, 죄송합니다. 내 잘못, 질문을 수정합니다. –