#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()