WEB/Django prac

[Django prac][Django prac][DB N:M 팔로우] 4.

bay07 2024. 4. 12. 15:17

회원은 0명 이상의 팔로워를 가질 수 있다. 

그리고 0명 이당의 다른 회원들을 following 할 수 있다


# accounts > models.py 

참조

내가 팔로우하는 사람들 (followings)

역참조 

상대방의 입장에서 나는 팔로워 중 한 명이다 (followers)

더보기
from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
class User(AbstractUser):
    followings = models.ManyToManyField('self', symmetrical=False, related_name='followers')

# migrate 

 

python manage.py makemigrations
python manage.py migrate

# DB에서 확인하기