Skip to content

Commit

Permalink
추가: Friend 테이블 unique constraint 추가
Browse files Browse the repository at this point in the history
- 고유한 레코드외 중복 레코드 생성시 IntegrityError 생성
  • Loading branch information
Sahayana committed Oct 25, 2023
1 parent 0b6af84 commit 9078033
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/friend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ class Friend(BaseModel):
)

def __str__(self) -> str:

return f"Friend connection between {self.user.nickname} and {self.target_user.nickname}"

class Meta:
constraints = [
models.UniqueConstraint(
fields=["user", "target_user"], name="unique_friend"
)
]

0 comments on commit 9078033

Please sign in to comment.