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

4/1 이가현 #1 #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions [1주차]/gahyeon2/gaga.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("i'm gaga")
25 changes: 25 additions & 0 deletions [3주차]/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.contrib import admin

from blog.models import Post, Category, Tag, Comment


@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ('id', 'category', 'tag_list', 'title', 'description', 'image', 'create_dt', 'update_dt', 'like')

def tag_list(self, obj):
return ','.join([t.name for t in obj.tags.all()])

def get_queryset(self, request):
return super().get_queryset(request).prefetch_related('tags')
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'description')

@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
list_display = ('id', 'name')

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ('id', 'post', 'short_content', 'create_dt', 'update_dt')
41 changes: 41 additions & 0 deletions [3주차]/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.db import models

# N 테이블에 field 정의
class Post(models.Model):
category = models.ForeignKey('Category', on_delete=models.SET_NULL, blank=True,null=True)
tags = models.ManyToManyField('Tag', blank=True)
title = models.CharField('TITLE',max_length=50)
description = models.CharField('DESCRIPTION', max_length=100,blank=True, help_text='simple one-line text.')
image = models.ImageField('IMAGE',upload_to='blog/%Y/%m/',blank=True,null=True)
content = models.TextField('CONTENT')
create_dt = models.DateTimeField('CREATE DT',auto_now_add=True)
update_dt = models.DateTimeField('UPDATE DT', auto_now=True)
like = models.PositiveSmallIntegerField('LIKE',default=0)

def __str__(self):
return self.title

class Category(models.Model): # P:C = N : 1
name = models.CharField(max_length=50,unique=True)
description = models.CharField('DESCRIPTION',max_length=100,blank=True,help_text='simple one-line text.')

def __str__(self):
return self.name

class Tag(models.Model): # P:T = N : N
name = models.CharField(max_length=50)

def __str__(self):
return self.name

class Comment(models.Model): # P:C = 1 : N
post = models.ForeignKey(Post,on_delete=models.CASCADE,blank=True,null=True)
content = models.TextField('CONTENT')
create_dt = models.DateTimeField('CREATE DT',auto_now_add=True)
update_dt = models.DateTimeField('UPDATE DT',auto_now=True)

@property
def short_content(self):
return self.content[:10]
def __str__(self):
return self.short_content