Django 간단한 회원가입 기능 만들기 - 2

pitbull terrier·2020년 9월 18일
0

Django

목록 보기
7/9

models.py 작성

간단하게 회원가입 기능을 만들어본다고 했다.
models.py를 작성해보겠다.
나는 앞시간에 fcuser라는 app을 만들었고 fcuser폴더 안에 있는 models.py를 작성한다.

models.py

from django.db import models

class Fcuser(models.Model):
	username 		= models.CharField(max_length = 64, 
    				    			verbose_name = '사용자명')
    	password 		= models.CharField(max_length = 64, 
    				    			verbose_name = '비밀번호')
        registerd_dttm 		= models.DateTimeField(auto_now_add = True,
        						verbose_name = '등록시간')
        class Meta:
            db_table = 'fcuser'

자 이렇게 작성을 해보자.
username,password 이라는 변수에 models.CharField라고 이 변수는 문자열이다 라고 지정을 해주었고 최대 길이는 64바이트로 지정해주었다.
verbose_name은 추후에 admin을 사용할건데 그 필드에 대한 이름이라고 보면 된다.
registerd_dttm은 DateTimeField로 지정해주었고
auto_now_add = True는 현재시간을 알려주는 것이다.
따로 코드를 짜지 않고도 django기능으로 끌어다 쓸 수 있다.
class Meta는 가볍게 테이블명을 지정해준다고 생각하면 된다.

심플하게 models.py 작성이 끝났다.

profile
yoonbitnara.github.io

0개의 댓글