๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ฐ˜์‘ํ˜•

๐Ÿ’ป Deep Wide Programming/Django

(12)
Django Admin ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•˜๊ธฐ ๊ธฐ๋ณธ์ ์ธ ์žฅ๊ณ  ์–ด๋“œ๋ฏผ ์„ธํŒ…์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. [admin.py]์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค€๋‹ค. admin์„ imortํ•ด, admin.ModelAdmin์— ์ƒ์†์‹œํ‚จ๋‹ค. from django.contrib import admin from . import models @admin.register(models.User) class CustomUserAdmin(admin.ModelAdmin): """Custom User Admin""" pass ์—ฌ๊ธฐ์„œ ๊ธฐ์กด ์–ด๋“œ๋ฏผ์— ๋”ํ•ด ํ™•์žฅํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  CustomUserAdmin์„ UserAdmin์— ์ƒ์†์‹œํ‚จ๋‹ค. from django.contrib import admin from django.contrib.auth.admin import UserAdmin..
Django Templates 1. ๋ฐ˜๋ณต๋˜๋Š” html ๊ตฌ์กฐ๊ฐ€ ์žˆ๋‹ค๋ฉด, templates ํด๋”๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๊ณ , ๊ทธ ์•ˆ์— base.html์„ ๋งŒ๋“ ๋‹ค. 1-2. ๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ๋‹ค๋ฅธ ํŒŒ์ผ์—์„œ extendํ•ด์„œ ์‚ฌ์šฉํ•ด์ค€๋‹ค. ๋งˆ์น˜ ๋ถ€๋ชจ-์ž์‹ ํด๋ž˜์Šค์ฒ˜๋Ÿผ. ์˜ˆ๋ฅผ ๋“ค์–ด, home.html์ด ์žˆ๋‹ค๋ฉด ํ•ด๋‹น html์˜ ์ตœ์ƒ๋‹จ์— ๋‹ค์Œ์˜ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค. {% extends "base.html" %} ๊ทธ๋Ÿฌ๋ฉด, base.html์—์„œ ๋งŒ๋“  html ์ฝ”๋“œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋œ๋‹ค. 2. ๋‚˜์•„๊ฐ€, ํ•ด๋‹น html์•ˆ์—๋‹ค๊ฐ€ ์›ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ฃผ์ž…ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ๋‹ค์‹œ ๋งํ•ด, home.html์ด๋ผ๋Š” ์ž์‹ ํ…œํ”Œ๋ฆฟ์ด base.html์ด๋ผ๋Š” ๋ถ€๋ชจ ํ…œํ”Œ๋ฆฟ์— ์›ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ง‘์–ด๋„ฃ์„ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š” ๊ฒƒ์ด๋‹ค. ๋ฐ”๋กœ, block์„ ์ด์šฉํ•ด์„œ ๊ฐ€๋Šฅํ•˜๋‹ค. ๋ถ€๋ชจํ…œํ”Œ๋ฆฟ์ธ base.html์— block..
Django ์ „๋ฐ˜๋ถ€ ์ •๋ฆฌ & ๋ณต์Šต Django Model ~ Admin๊นŒ์ง€ Quick Review Config - master folder ๋‚˜๋จธ์ง€ ์ƒ์„ฑํ•ด์ค€ ํด๋”๋“ค์€, ๋ชจ๋‘ application์ด๋‹ค. application = function์˜ group ์ฒ˜์Œ์—, models & admin ์„ ๊ฑด๋“œ๋ฆผ. ์žฅ๊ณ ๊ฐ€ ์šฐ๋ฆฌ๊ฐ€ ์“ด ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•จ. ํŒŒ์ด์ฌ ์ฝ”๋“ค๋ฅด SQL๋ฌธ์œผ๋กœ ์ž๋™์œผ๋กœ ๋ฐ”๊ฟ”์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์†Œํ†ตํ•ด์ค€๋‹ค. models.py์— ์ ์€ ์ฝ”๋“œ๋Š”, ์žฅ๊ณ ๊ฐ€ ์•Œ์•„์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”๋กœ ๋งŒ๋“ค์–ด์ค€๋‹ค. Model์€ fields๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. textField, CharField, ๋“ฑ๋“ฑ๋“ฑ. model์„ ์ง์ ‘ ๋ณด๋ ค๋ฉด, admin ํŒจ๋„์„ ๋ณด๋ฉด ๋œ๋‹ค. admin.py์—์„œ ์ผ๋‹จ modeldmf Class๋กœ registerํ•ด์ค€๋‹ค. @admin.register(mod..
์žฅ๊ณ  ๊ณต๋ถ€์— ๋„์›€๋˜๋Š” ์‚ฌ์ดํŠธ ๋งํฌ & ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ ์–ธ์–ด opentutorials.org/module/4034/24665 ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ(Template) ์–ธ์–ด - Django ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ(Template) ์–ธ์–ด 2019-04-18 19:37:51 ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ ์–ธ์–ด ์ง€๋‚œ ํ† ํ”ฝ์—์„œ {% load static %}์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์˜€๋Š”๋ฐ, ์ด๋Š” ์ด๋ฒˆ ํ† ํ”ฝ์—์„œ ๊ณต๋ถ€ํ•  ํ…œํ”Œ๋ฆฟ ํƒœ๊ทธ๋ฅผ ํ™œ์šฉํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์žฅ๊ณ  ํ…œํ”Œ๋ฆฟ ์–ธ์–ด๋Š” opentutorials.org ๋‹ค์Œ์— ํ•„์š”ํ•  ๋•Œ ๋‹ค์‹œ ์ฐพ์•„๋ณด๋ ค๊ณ  ๋ฉ”๋ชจ~.~
[โ›บ๏ธDjango] MORE about ADMINS + a #ํ•™์Šต๋ฉ”๋ชจ ๋ณดํ˜ธ๋˜์–ด ์žˆ๋Š” ๊ธ€์ž…๋‹ˆ๋‹ค.
[โ›บ๏ธDjango] MODELS AND QUERYSETS ๋ฉ”๋ชจ ๐Ÿ“Œ์žฅ๊ณ  ์„ค์ •๊ณผ ์žฅ๊ณ  ๋ชจ๋ธ๋กœ ํ”„๋กœ์ ํŠธ์™€ ์†Œํ†ตํ•˜๋Š” ๋ฒ• pipenv shell python manage.py shell from users.models import User ๐Ÿ“ŒUser.objects ๐Ÿ’ฅ manager: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ๋ถ€ํ„ฐ elements๋ฅผ ๊ฐ€์ ธ์˜ค๊ฒŒ ํ•ด์ฃผ๋Š”๋ฐ, SQL์„ ์“ฐ์ง€ ์•Š๊ณ ๋„ ํŒŒ์ด์ฌ์„ ์ด์šฉํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ฒŒ ํ•ด์ค€๋‹ค! ๐Ÿ‘‰The most Sexiest part of Django! manager๋Š” object ์•ˆ์— ์žˆ๋‹ค ๐Ÿ”— ์ฐธ๊ณ  docs.djangoproject.com/en/2.2/topics/db/queries/ Making queries | Django documentation | Django Django The web framework for perfectionists with deadlines...
[โ›บ๏ธ Django] Django basic #3 #4 ๋ณต์Šต ๋ฉ”๋ชจ ๐Ÿ“ŒUserAdmin (Django๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์–ด๋“œ๋ฏผ ํŒจ๋„) ํŒŒ๋ž€ ๋ผ์ธ ์žˆ๋Š” ๋ฐ•์Šค = fieldset ๊ธฐ๋ณธ ์žฅ๊ณ  ์–ด๋“œ๋ฏผ fieldset + ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ  ์‹ถ๋‹ค๋ฉด ํ•˜๋‹จ์ฒ˜๋Ÿผ. banana fieldset์„ ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค. from django.contrib import admin from django.contrib.auth.admin import UserAdmin from . import models # Register your models here. @admin.register(models.User) class CustomUserAdmin(UserAdmin): """ Custom User Admin """ fieldsets = UserAdmin.fieldsets + ( ("Banana", {"fields": ("..
[โ›บ๏ธํด๋ก ์ฝ”๋”ฉ] django App ๋งŒ๋“ค๊ธฐ ์‹ค์Šต #๋ฉ”๋ชจ ๐Ÿ“Œ ํ•„์š”ํ•œ App folder๋“ค ์ƒ์„ฑ ์ดํ›„, 1. ์ฒซ์งธ, Config ํด๋”์˜ settings.py์˜ INSTALLED_APPS ์•ˆ์— ์ƒ์„ฑํ•ด์ค€ ํ•˜์œ„ ์•ฑ๋“ค์„ ๋„ฃ์–ด์ค€๋‹ค. [๊ฐ์ฒด์ง€ํ–ฅ!]ex. users ํด๋”์˜ apps.py์˜ UsersConfig ํด๋ž˜์Šค, rooms ํด๋”์˜ apps.py์˜ UsersConfig ํด๋ž˜์Šค 2. ๋‘˜์งธ, models.py์—์„œ ํ•ด๋‹น App์˜ ๋ชจ๋ธ์„ ์ƒ์„ฑํ•ด์ค€๋‹ค.์ผ๋‹จ ์žฅ๊ณ ์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” ๊ธฐ๋ณธ๊ฐ’์€ ๋‹ค์Œ๊ณผ ๊ฐ™๊ณ , โŽˆ ์ปค์Šคํ…€ ํ•ด์ฃผ๊ณ  ์‹ถ๋‹ค๋ฉด, AbstractUser์„ ์ž„ํฌํŠธํ•ด์˜จ๋‹ค. 3. ์…‹์งธ, admin.py์—์„œ Model์„ importํ•˜๊ณ , ํ•ด๋‹นApp์–ด๋“œ๋ฏผ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•ด ์–ด๋“œ๋ฏผ ํ™˜๊ฒฝ์„ ์„ธํŒ…ํ•ด์ค€๋‹ค. ๐Ÿ“ŒTip! ๋ชจ๋“  App admin.py์— ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค˜์•ผํ•  ๋•Œ! => App CoreCore..

728x90
๋ฐ˜์‘ํ˜•