#8 MORE ADMINS! - WONILLISM/Clone_airbnb GitHub Wiki
created by wopark
created by mki
8.3 MEDIA_ROOT settings.py MEDIA_ROOT = ์ ๋๊ฒฝ๋ก! BASE_DIR MEDIA_ROOT = os.path.join(BASE_DIR, "uploads") .gitignore uploads/ file = models.ImageField(upload_to="room_photos") avatar = models.ImageField(upload_to="avatars", blank=True)
8.4 URL MEDIA_URL = "media/" slash๋ก ๋๋์ผ ํ๋ค. ํด๋ ๋ช ์ ๊ฐ์ถ๋ ๊ธฐ๋ฅ ์์ ๋ถ๋ถ๋... Amazon s3 ์ ๋ก๋ ํ์ผ์ ๋ค๋ฅธ ์๋ฒ์์ ํ ์ ์๋ค. settings๋ฅผ... ํ๋ก๋์ ์ ๋ผ์ด๋ธ. ๊ฐ๋ฐ์... DEBUG = True ๋ ธ๋ ์๋ฌ ๋ฉ์์ง. False๋ผ๋ฉด 404๋ฉ์์ง static helper
from django.conf.urls.static import static if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) http://127.0.0.1:8000/media/avatars/2.jpeg ์ฝ๋์ ๋ฏธ๋์ด ์๋ฒ๋ฅผ ๋ถ๋ฆฌํ์. Amazon heroku
8.5 photo admin๋ง๋ค๊ธฐ list_display = ("str", "get_thumbnail")
def get_thumbnail(self, obj):
print(dir(obj.file))
return ""
get_thumbnail.short_description = "Thumbnail"
obj.file์ ํจ์๋ค์ ์ฌ์ฉํ์.
def get_thumbnail(self, obj):
return obj.file.url
photo admin์์ ๋ฐ๋ก ๋งํฌ๋ก ์ด๋ํ๊ณ ์ถ๋ค.
from django.utils.html import mark_safe
8.6 room์์ photos๋ฅผ ์ถ๊ฐํ์. ์๋ฌธ์๋ฅผ ๋๋ฌธ์๋ก ๋ฐ๊พธ๊ธฐ ์ ์ ํธ์คํธ๊ฐ ์์ฒญ ๋ง์์ง๋ง ๋ฆฌ์คํธ๋ ๋ง์์ง๋ค. ๊ทธ๊ฑธ ํผํ๊ณ ์ถ๋ค. raw_id_fields = ("host",)
admin์์ ๋ ๋ค๋ฅธ admin class InlineModelAdmin
TabularInline
class PhotoInline(admin.TabularInline):
model = models.Photo
StackedInline
8.7 save method ์ฅ๊ณ ๋ ์ ๋ง ๋ง์ class๊ฐ ์๋ค. ์ฅ๊ณ ์ ๋ชจ๋ ๋ชจ๋ธ์ save() method๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
OOP
super()
8.8 save() delete()
super๋ฅผ ํธ์ถํด์ผ ์ ์ฉ๋๋ค. args kwargs๋ฅผ ์์ง๋ง์ธ์. ์ด๋ ค์์ ์ฌ๋๋ค์ overrideํ ์๋๋ ๋ชปํ๋ค. Model.save() save_model()