- SQL
- Tree
- N:1
- delete
- Queue
- 스택
- 백트래킹
- 쟝고
- 뷰
- stack
- count
- outer join
- Article & User
- 그리디
- migrations
- 트리
- M:N
- Django
- 큐
- DB
- drf
- regexp
- update
- Vue
- create
- ORM
- 이진트리
- 통계학
- 완전검색
- distinct
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
목록쟝고 (44)
데이터 분석 기술 블로그
Django에서는 'ManyToManyField'로 중개모델을 자동으로 생성합니다.1. Django ManyToManyField환자 모델에 ManyToManyField를 작성합니다.# hospitals/models.pyclass Patient(models.Model): # ManyToManyField 작성 doctors = models.ManyToManyField(Doctor) name = models.TextField() def __str__(self): return f'{self.pk}번 환자 {self.name}'# Reservation Class 주석 처리데이터베이스 초기화 후 Migration 진행 및 shell_plus 실행합니다.생성된 중개 테이블 h..
1. 예약 모델 생성환자 모델의 외래 키를 삭제하고 별도의 예약 모델을 새로 생성합니다.예약 모델은 의사와 환자에 각각 N:1 관계를 갖습니다.# hospitals/models.py# 외래 키 삭제class Patient(models.Model): name = models.TextField() def __str__(self): return f'{self.pk}번 환자 {self.name}'# 중개모델 작성class Reservation(models.Model): doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE) patient = models.ForeignKey(Patient, on_delete=models..
1. Many to many relationships (N:M or M:N)한 테이블의 0개 이상의 레코드가 다른 테이블의 0개 이상의 레코드와 관련된 경우입니다.양쪽 모두에서 N:1 관계를 가집니다.1-1. M:N 관계의 역할과 필요성 이해하기'병원 진료 시스템 모델 관계'를 만들며 M:N 관계의 역할과 필요성을 이해합니다.환자와 의사 2개의 모델을 사용하여 모델 구조 구상합니다.2. N:1의 한계의사와 환자 간 모델 관계 설정한 명의 의사에게 여러 환자가 예약할 수 있다고 설계합니다.# hospital/models.pyclass Doctor(models.Model): name = models.TextField() def __str__(self): return f'{sel..
1. 댓글 DELETE댓글 삭제 요청 사용자와 댓글 작성 사용자를 비교하여 본인의 댓글만 삭제 할 수 있도록 합니다.# articles/views.pydef commets_delete(request, article_pk, comment_pk): comment = Comment.objects.get(pk=comment_pk) if request.user == comment.user: comment.delete() return redirect('articles:detail', article_pk)해당 댓글의 작성자가 아니라면, 댓글 삭제 버튼을 출력하지 않도록 합니다. {% for comment in comments %} {{ comment.user }} - {..
1. 댓글 CREATE댓글 작성 시 이전에 게시글 작성할 때와 동일한 에러가 발생합니다. 댓글의 user_id 필드 데이터가 누락되었기 때문입니다.댓글 작성 시 작성자 정보가 함께 저장할 수 있도록 작성합니다.# articles/views.pydef comments_create(request, pk): article = Article.objects.get(pk=pk) comment_form = CommentForm(request.POST) if comment_form.is_valid(): comment = comment_form.save(commit=False) comment.article = article comment.user = request.u..
1. Comment-User 모델 관계 설정User 외래 키를 정의합니다.# articles/models.pyclass Comment(models.Model): article = models.ForeignKey(Article, on_delete=models.CASCADE) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) content = models.CharField(max_length=200) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)2. Migrat..
1. 게시글 READ 각 게시글의 작성자 이름을 출력한다. {% for article in articles %} 작성자 : {{ article.user }} 글 번호 : {{ article.pk }} 글 제목 : {{article.title }} 글 내용: {{ article.content }} {% endfor %} 2. 게시글 UPDATE 게시글 수정 요청 사용자와 게시글 작성 사용자를 비교하여 보인의 게시글만 수정할 수 있도록 합니다. # articles/views.py @login_required def update(request, pk): article = Article.objects.get(pk=pk) if request.user == article.user: if request.method ..
게시글 CREATE 기존 Article Form 출력 변화를 확인합니다. User 모델에 대한 외래 키 데이터 입력을 위해 불필요한 input이 출력됩니다. ArticleForm 출력 필드를 수정합니다. # articles/forms.py class ArticleForm(forms.ModelForm): class Meta: model = Article fields = ('title', 'content',) 게시글 작성 시 에러 발생가 발생하면 user_id 필드 데이터가 누락되었기 때문입니다. 게시글 작성 시 작성자 정보가 함께 저장될 수 있도록 save의 commit 옵션을 활용합니다. # articles/views.py @login_required def create(request): if reque..