Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

모델 생성입니다. #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions DRFproject/DRFproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

INSTALLED_APPS = [
#myapp 추가
'loinz',
'lionz',
# third party app
'rest_framework',
# Basic App
'django.contrib.admin',
'django.contrib.auth',
Expand All @@ -31,7 +33,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'seminar_project.urls'
ROOT_URLCONF = 'DRFproject.urls'

TEMPLATES = [
{
Expand All @@ -49,7 +51,7 @@
},
]

WSGI_APPLICATION = 'seminar_project.wsgi.application'
WSGI_APPLICATION = 'DRFproject.wsgi.application'

DATABASES = {
'default': {
Expand Down
1 change: 0 additions & 1 deletion DRFproject/DRFproject/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib import admin
from django.urls import path, include

from util import views

urlpatterns = [
path('admin/', admin.site.urls),
Expand Down
4 changes: 3 additions & 1 deletion DRFproject/lionz/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib import admin

from .models import *
# Register your models here.
admin.site.register(Assigment) #Assigment 모델 등록
admin.site.register(Submission) # Submission 모델 등록
38 changes: 37 additions & 1 deletion DRFproject/lionz/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
from django.db import models

# Create your models here.
class Member(models.Model): # Member 모델 정의
name = models.CharField(max_length=20) # 멤버 이름 저장

class Category(models.Model): #카테고리 모델``
name = models.CharField(max_length=20,unique=True) #카테고리 이름, 중복 불가능

class Assigment(models.Model): # 과제 생성 모델
title = models.CharField(max_length=50) #제목
created_at = models.DateTimeField(auto_now_add=True) #생성일자
deadline = models.DateTimeField() #마감일자
# part로 모델을 따로 만들었다가,3개의 파트로 과제가 분류만 되면 되니 과제 모델 안에 넣어도 무방할 것 같아서
#이렇게 구현하고 view에서는 filter 메소드 통해서 구분하는 방법으로 생각해봤습니다.
# 이부분은 확인하시고 피드백해주세요!!
part = models.CharField(max_length=3, choices=[
('BE', 'BE'),
('FE', 'FE'),
('ALL', 'All')
])
catagory_id = models.ForeignKey(Category, on_delete=models.CASCADE,related_name='assignments')
# 카테고리:과제 = 1:N 관계 설정
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카테고리랑 과제를 다대다 관계로 설정하고, 중간에 모델을 하나 더 만들어서 다대다 관계를 1:N, N:1로 푸는 방식은 어떨까요??

content = models.TextField() #과제 내용
githubUrl = models.URLField() #github 주소


class Submission(models.Model):
member_id = models.ForeignKey(Member, on_delete=models.CASCADE,related_name='assignments')
# 멤버:제출물 = 1:N 관계 설정,멤버가 삭제되면 과제도 삭제
assignment_id = models.ForeignKey(Assigment, on_delete=models.CASCADE,related_name='submissions')
# 과제:제출물 = 1:N 관계 설정, 과제가 삭제되면 제출물도 삭제
content = models.TextField() #제출물 내용
githubUrl = models.URLField() #github 주소
created_at = models.DateTimeField(auto_now_add=True) #생성일자(제출일자)





8 changes: 8 additions & 0 deletions DRFproject/lionz/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from django.shortcuts import render
import json
from django.http import JsonResponse
from .models import *
from django.shortcuts import get_object_or_404
#.serializers , REST프레임워크 import 추가 필요

# Create your views here.

# 고려해야 할 점 1) assgiment를 post 할 때 카테고리가 없으면 카테고리를 생성하고, 있으면 해당 카테고리에 추가해야함
# 고려해야 할 점 2) be,fe,all에 따라 파트를 구분하는 로직이 필요함
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# drf-advanced-team4
drf실습 4팀 과제 레포입니다.

Binary file added requirements.txt
Binary file not shown.
33 changes: 33 additions & 0 deletions 모델 생성 설명.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

관리자가 올리는 과제 글 -> 과제
과제 제출하는 사람이 올리는 글 -> 제출물
로 통일했습니당

- view 고려하면서 model 수정을 고려해봐야 할 점은 part 부분인 것 같아요.
제 생각에는 part가 BE,FE,ALL만 존재하니 따로 모델을 안만들고, 과제 모델 안에 charfield로 만들어서 choice옵션으로 3개가 선택 가능하도록 했습니다. view에서는 filter 메소드 사용하거나 다른 방법으로 조건 처리를 하여 all일 떄, fe랑 be인 것을 다 보여주면 될 것 같아요.! <-이건 제가 하면서 생각한거라 다른 방법으로 하거나, 아예 모델의 수정이 필요하다면 수정해도 좋습니다.

- 카테고리부분에서 새로운 카테고리를 만들면 새롭게 데이터가 입력되고, 기존의 카테고리면 기존의 카테고리로 분류되도록 로직이 필요합니다!(view에서)




-현재 모델 기준 json 예시

1. Assigiment 모델

{
"title": "장고 모델 과제",
"deadline": "2024-05-07T23:59:00",
"part": "BE",
"category_id": 1,<-요거를 이름으로 제공하고, 이미 있으면 그대로 사용하고, 아니면 새로 만드는 로직은 view에서 구현해야 할 것 같아요
"content": "장고 모델 기본 과제입니다. ~를 사용해서 구현해주세요",
"githubUrl": "https://github.com/example/django-project"
}

2. Submssion 모델
{
"member_id": 2,
"assignment_id": 3,
"content": "장고 모델 기본 과제 제출합니다.",
"githubUrl": "https://github.com/user/submission-repo"
}