from django.db import models
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill
from django.conf import settings

def post_image_path(instance,filename):
    return 'posts/images/{}.jpg'.format(filename)
    
# Create your models here.
class Post(models.Model):
    user=models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
    content=models.TextField()
    # image=models.ImageField(blank=True) #blank=True:이미지를 업로드하지 않아도 post만들기 가능하다는 의미.
    like_users=models.ManyToManyField(settings.AUTH_USER_MODEL,related_name='like_posts')
    
class Image(models.Model):
    post=models.ForeignKey(Post, on_delete=models.CASCADE)
    file=ProcessedImageField(
            upload_to=post_image_path, #저장 위치
            processors=[ResizeToFill(600,600)], #처리할 작업 목록
            format='JPEG', #저장 포맷
            options={'quality':90}, #옵션
        )
    
class Comment(models.Model):
    user=models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
    post=models.ForeignKey(Post,on_delete=models.CASCADE)
    content=models.TextField()
    
    
    