본문 바로가기

전체 글

(977)
[Django]Better Validation on Update Views CodingEntrepreneurs Django 강의 정리 forms> from django import forms from .models import BlogPost class BlogPostForm(forms.Form): title = forms.CharField() slug = forms.SlugField() content = forms.CharField(widget=forms.Textarea) class BlogPostModelForm(forms.ModelForm): # title = forms.CharField() class Meta: model = BlogPost fields = ["title", "slug", "content"] def clean_title(self, *args, **kwar..
[Django]Update View with Model Form CodingEntrepreneurs Django 강의 정리 forms> from django import forms from .models import BlogPost class BlogPostForm(forms.Form): title = forms.CharField() slug = forms.SlugField() content = forms.CharField(widget=forms.Textarea) class BlogPostModelForm(forms.ModelForm): # title = forms.CharField() class Meta: model = BlogPost fields = ["title", "slug", "content"] # def clean_title(self, *args, **kw..
[Django]Logged In user & Forms CodingEntrepreneurs Django 강의 정리 views> from django.contrib.auth.decorators import login_required from django.contrib.admin.views.decorators import staff_member_required from django.http import Http404 from django.shortcuts import render, get_object_or_404 # Create your views here. from .models import BlogPost from .forms import BlogPostModelForm # CRUD # GET -> Retrieve / List # POST -> Create ..
[Django]Associate Blog Post to a User with Foreign Keys CodingEntrepreneurs Django 강의 정리 AUTH_USER_MODEL> 1. 사용자를 나타내는 데 사용할 모델 2. 기본 사용자 모델을 오버라이드 ForeignKey> 1. 다대일 관계. 2. 두개의 위치 인수, 즉 모델과 관련된 클래스와 on_delete옵션이 필요 models> from django.conf import settings from django.db import models # Create your models here. User = settings.AUTH_USER_MODEL class BlogPost(models.Model): # blogpost_set > queryset # id = models.IntegerField() # pk user = models.Forei..
[Django]Login Required CodingEntrepreneurs Django 강의 정리 @login_required> 1. 사용자가 로그인한 경우 정상적으로 실행 2. is_active사용자에게 플래그를 지정하지만 기본 AUTHENTICATION_BACKENDS는 비활성 사용자를 거부 가이드 @staff_member_required> 1. 사용자의 등급이 멤버인 경우 정상적으로 실행 views> from django.contrib.auth.decorators import login_required from django.contrib.admin.views.decorators import staff_member_required from django.http import Http404 from django.shortcuts import ..
[Django]Validate Data on Fields CodingEntrepreneurs Django 강의 정리 forms> from django import forms from .models import BlogPost class BlogPostForm(forms.Form): title = forms.CharField() slug = forms.SlugField() content = forms.CharField(widget=forms.Textarea) class BlogPostModelForm(forms.ModelForm): # title = forms.CharField() class Meta: model = BlogPost fields = ["title", "slug", "content"] def clean_title(self, *args, **kwar..
[Django]Model Form CodingEntrepreneurs Django 강의 정리 form fields> 1. 양식의 필드를 정의 가이드 form> from django import forms from .models import BlogPost class BlogPostForm(forms.Form): title = forms.CharField() slug = forms.SlugField() content = forms.CharField(widget=forms.Textarea) class BlogPostModelForm(forms.ModelForm): title = forms.CharField() class Meta: model = BlogPost fields = ["title", "slug", "content"] models>..
[Django]Saving Data from a Django Form CodingEntrepreneurs Django 강의 정리 form에 입력 받은 데이터를 저장하고 새로운 페이지를 갱신> forms> from django import forms class BlogPostForm(forms.Form): title = forms.CharField() slug = forms.SlugField() content = forms.CharField(widget=forms.Textarea) create.html> {% extends "form.html" %} form.html> {% extends "base.html" %} {% block content %} {% if title %} {{ title }} {% endif %} {% csrf_token %} {{ form.as_p }..