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

이라령: 240521 #30

Open
wants to merge 13 commits into
base: bysunfruto
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
Empty file.
5 changes: 5 additions & 0 deletions Dfirstproject/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import *
# Register your models here.

admin.site.register(CustomUser)
6 changes: 6 additions & 0 deletions Dfirstproject/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
8 changes: 8 additions & 0 deletions Dfirstproject/accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from dataclasses import field
from django.contrib.auth.forms import UserCreationForm
from .models import CustomUser

class RegisterForm(UserCreationForm):
class Meta:
model=CustomUser
fields=['username', 'password1', 'password2', 'nickname', 'university', 'location', 'interest']
48 changes: 48 additions & 0 deletions Dfirstproject/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 5.0.3 on 2024-05-09 10:31

import django.contrib.auth.models
import django.contrib.auth.validators
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='CustomUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('nickname', models.CharField(max_length=100)),
('university', models.CharField(max_length=50)),
('location', models.CharField(max_length=200)),
('interest', models.CharField(max_length=100, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
Empty file.
10 changes: 10 additions & 0 deletions Dfirstproject/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models

from django.contrib.auth.models import AbstractUser


class CustomUser(AbstractUser):
nickname = models.CharField(max_length=100)
university = models.CharField(max_length=50)
location = models.CharField(max_length=200)
interest = models.CharField(max_length=100, null=True)
6 changes: 6 additions & 0 deletions Dfirstproject/accounts/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Login</h1>
<form action="{% url 'login' %}" method="post">
{% csrf_token %}
{{ form.as_p}}
<button type="submit">로그인</button>
</form>
6 changes: 6 additions & 0 deletions Dfirstproject/accounts/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Sign Up</h1>
<form action="{% url 'signup' %}" method="post">
{% csrf_token %}
{{ form.as_p}}
<button type="submit">회원가입</button>
</form>
3 changes: 3 additions & 0 deletions Dfirstproject/accounts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
35 changes: 35 additions & 0 deletions Dfirstproject/accounts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.shortcuts import render, redirect
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import authenticate, login, logout
from accounts. forms import RegisterForm

# Create your views here.

def login_view(request):
if request.method=='POST':
form=AuthenticationForm(request=request, data=request.POST)
if form.is_valid():
username=form.cleaned_data.get('username')
password=form.cleaned_data.get('password')
user=authenticate(request=request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('list')
else:
form=AuthenticationForm()
return render(request, 'login.html', {'form':form})

def logout_view(request):
logout(request)
return redirect('list')

def signup_view(request):
if request.method=='POST':
form=RegisterForm(request.POST)
if form.is_valid():
user=form.save()
login(request, user)
return redirect('list')
else:
form=RegisterForm()
return render(request, 'signup.html', {'form':form})
3 changes: 3 additions & 0 deletions Dfirstproject/community/static/css/test2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: blue;
}
14 changes: 14 additions & 0 deletions Dfirstproject/community/Forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import forms
from .models import Question, Comment

class QuestionForm(forms.ModelForm):
class Meta:
model=Question
fields=['title', 'content', 'photo']

class CommentForm(forms.ModelForm):
class Meta:
model=Comment
fields=['username', 'comment_text']

##수정sou
Empty file.
9 changes: 9 additions & 0 deletions Dfirstproject/community/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from community.models import *

# Register your models here.

admin.site.register(Question)
admin.site.register(Comment)
admin.site.register(HashTag)
admin.site.register(Like)
6 changes: 6 additions & 0 deletions Dfirstproject/community/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CommunityConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'community'
23 changes: 23 additions & 0 deletions Dfirstproject/community/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.4 on 2024-04-08 04:09

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=50, verbose_name='Title')),
('upload_time', models.DateTimeField(unique=True)),
('content', models.TextField(verbose_name='Content')),
],
),
]
17 changes: 17 additions & 0 deletions Dfirstproject/community/migrations/0002_rename_post_question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.0.4 on 2024-04-08 04:13

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('community', '0001_initial'),
]

operations = [
migrations.RenameModel(
old_name='Post',
new_name='Question',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-08 04:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('community', '0002_rename_post_question'),
]

operations = [
migrations.AlterField(
model_name='question',
name='upload_time',
field=models.DateTimeField(verbose_name='date published'),
),
]
25 changes: 25 additions & 0 deletions Dfirstproject/community/migrations/0004_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.3 on 2024-04-09 10:40

import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('community', '0003_alter_question_upload_time'),
]

operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=20)),
('comment_text', models.TextField()),
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='community.question')),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.3 on 2024-04-09 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('community', '0004_comment'),
]

operations = [
migrations.CreateModel(
name='HashTag',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('hashtag', models.CharField(max_length=100)),
],
),
migrations.AddField(
model_name='question',
name='hashtag',
field=models.ManyToManyField(to='community.hashtag'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.0.3 on 2024-04-11 07:23

import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('community', '0005_hashtag_question_hashtag'),
]

operations = [
migrations.AddField(
model_name='question',
name='likes_count',
field=models.IntegerField(default=0),
),
migrations.CreateModel(
name='Like',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=20)),
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='likes', to='community.question')),
],
),
]
18 changes: 18 additions & 0 deletions Dfirstproject/community/migrations/0007_question_photo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-05-19 15:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('community', '0006_question_likes_count_like'),
]

operations = [
migrations.AddField(
model_name='question',
name='photo',
field=models.ImageField(blank=True, null=True, upload_to='community_photo'),
),
]
Empty file.
44 changes: 44 additions & 0 deletions Dfirstproject/community/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.db import models
from django.utils import timezone


# Create your models here.
class HashTag(models.Model):
hashtag=models.CharField(max_length=100)

def __str__(self):
return self.hashtag

class Question(models.Model):
title = models.CharField('Title', max_length=50, blank=True)
upload_time = models.DateTimeField('date published')
content = models.TextField('Content')
hashtag=models.ManyToManyField(HashTag)
likes_count=models.IntegerField(default=0)
photo = models.ImageField(blank=True, null=True, upload_to="community_photo")

def __str__(self):
return self.title

def summary(self):
return self.content[:100]

class Comment(models.Model):
post=models.ForeignKey(Question, related_name='comments', on_delete=models.CASCADE)
username=models.CharField(max_length=20)
comment_text=models.TextField()
created_at=models.DateTimeField(default=timezone.now)

def approve(self):
self.save()

def __str__(self) -> str:
return self.comment_text

class Like(models.Model):
post=models.ForeignKey(Question, related_name='likes', on_delete=models.CASCADE)
username=models.CharField(max_length=20)
created_at=models.DateTimeField(default=timezone.now)

def approve(self):
self.save()
8 changes: 8 additions & 0 deletions Dfirstproject/community/templates/add_comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{%block content%}
<h3>New Comment</h3>
<form method="POST" class="post-form">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn-default">등록</button>
</form>
{% endblock %}
Empty file.
Loading