class Team(models.Model): name = models.CharField(max_length=255, unique=True) createdAt = models.DateTimeField(auto_now_add=True) updatedAt = models.DateTimeField(auto_now=True) image = ProcessedImageField( null=True, blank=True, max_length=255, upload_to=teamImagePath, processors=[Thumbnail(256, 256)], # 처리할 작업 목룍 format='JPEG', # 최종 저장 포맷 options={'quality': 85}, default="user_1/profile", ) smallImage = ProcessedImageField( null=True, blank=True, max_length=255, upload_to=teamSmallImagePath, processors=[Thumbnail(64, 64)], # 처리할 작업 목룍 format='JPEG', # 최종 저장 포맷 options={'quality': 85}, default="user_1/profile", ) representative = models.ForeignKey( User, null=True, on_delete=models.CASCADE, related_name='representingTeam') # delete 조심히 할것 members = models.ManyToManyField(User, related_name='teams') def __str__(self): return f"Team {self.name} "
class Lecturer(models.Model): # 강사 user = models.ForeignKey(User) name = models.OneToOneField(Profile, on_delete=models.CASCADE, null=True) bank = models.CharField('은행명', max_length=50) account = models.CharField('계좌번호', max_length=50) career = models.TextField('경력사항') certification = models.TextField('자격증') profilephoto = ProcessedImageField(blank=False, upload_to='lecturer/post/%Y/%m/%d', processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 60}) idphoto = ProcessedImageField(blank=False, upload_to='lecturer/post/%Y/%m/%d', processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 60}) # 프로필사진, 신분증, 자격증사진(보류) imgfield class Meta: ordering = ['name'] def __str__(self): return str( self.name) #__str__ returned non-string (type Profile) > str()추가 def get_absolute_url(self): #return self.course.get_absolute_url() return reverse('course:lecturer', args=[self.id])
class Question(models.Model): title = models.CharField(max_length=20) issue_a = models.CharField(max_length=20) issue_b = models.CharField(max_length=20) image_a = ProcessedImageField( processors=[Thumbnail(200, 300)], # 처리할 작업 목록 format='JPEG', # 저장 포맷 options={'quality': 90}, # 추가 옵션들 upload_to='eithers/images', # 저장 위치(MEDIA_ROOT/article/images) ) image_b = ProcessedImageField( processors=[Thumbnail(200, 300)], # 처리할 작업 목록 format='JPEG', # 저장 포맷 options={'quality': 90}, # 추가 옵션들 upload_to='eithers/images', # 저장 위치(MEDIA_ROOT/article/images) ) def __str__(self): return self.title def get_absolute_url(self): # return f'/articles/{self.pk}/' # return reverse('articles:detail', args=[self.pk]) # articles/10/ return reverse('question:detail', kwargs={'question_pk': self.pk}) # articles/10/
class GalleryImage(models.Model): post = models.ForeignKey(InfomationImage, on_delete=models.PROTECT) name = models.CharField(max_length=100) gallery_image1 = ProcessedImageField( blank=True, processors=[Thumbnail(2000, 2000)], upload_to=get_image_path, format='JPEG', ) gallery_image2 = ProcessedImageField( blank=True, processors=[Thumbnail(2000, 2000)], upload_to=get_image_path, format='JPEG', ) gallery_image3 = ProcessedImageField( blank=True, processors=[Thumbnail(2000, 2000)], upload_to=get_image_path, format='JPEG', ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: verbose_name = '갤러리' verbose_name_plural = '갤러리'
class SampleSmsImage(models.Model): post = models.ForeignKey(SamplePost, on_delete=models.PROTECT) name = models.CharField(max_length=100) message_image1 = ProcessedImageField( blank=True, processors=[Thumbnail(2000, 2000)], upload_to=get_image_path, format='JPEG', ) message_image2 = ProcessedImageField( blank=True, processors=[Thumbnail(2000, 2000)], upload_to=get_image_path, format='JPEG', ) message_image3 = ProcessedImageField( blank=True, processors=[Thumbnail(2000, 2000)], upload_to=get_image_path, format='JPEG', ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: verbose_name = '(샘플)2G 핸드폰공유 이미지' verbose_name_plural = '(샘플)2G 핸드폰공유 이미지'
class Subject(models.Model): name = models.CharField(max_length=255) difficulty = models.CharField(max_length=45) rating = models.IntegerField() price = models.IntegerField() description = models.TextField() sub_image = models.ImageField(upload_to=sub_image_path) sub_thumbnail = ImageSpecField(source='sub_image', processors=[Thumbnail(250, 250)], format='jpeg', options={'quality': 60}) language = models.CharField(max_length=45) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) teacher = models.ForeignKey(Member, on_delete=models.CASCADE, related_name='my_lectures') student = models.ManyToManyField(Member, through='ClassRoom', related_name='subjects') def get_absolute_url(self): return reverse('subjects:subject_detail', args=[self.id]) class Meta: db_table = 'subjects' # ordering = ['-created_at'] def __str__(self): return self.name
class Post(models.Model): STATUS_CHOICES = ( ('d', 'Draft'), ('p', 'Published'), ('w', 'Withdraw'), ) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) title = models.CharField(max_length=100, verbose_name='제목', help_text='포스팅 내용을 입력해주세요 최대 100자') content = models.TextField(verbose_name='내용') photo = ProcessedImageField(blank=True, upload_to='blog/post/%Y/%m/%d', processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 60}) tags = models.CharField(max_length=100, blank=True) lnglat = models.CharField(max_length=50, blank=True, validators=[lnglat_validator], help_text='경도/위도 포맷으로 입력') status = models.CharField(max_length=1, choices=STATUS_CHOICES) tag_set = models.ManyToManyField('Tag', blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: ordering = ['id'] def __str__(self): return self.title def get_absolute_url(self): return reverse('post_detail', args=[self.id])
class User(AbstractUser): profileurl = models.CharField(max_length=200) followings = models.ManyToManyField('self', symmetrical=False, related_name='followers') image = ProcessedImageField(blank=True, processors=[Thumbnail(150, 200)], format='JPEG', options={'quality': 90})
class Article(models.Model): title = models.CharField(max_length=30) content = models.TextField() # image = models.ImageField(blank=True) # image_thumbnail = ImageSpecField( # source="image", # processors=[Thumbnail(200, 300)], # format="JPEG", # options={"quality": 90}, # ) image = ProcessedImageField( processors=[Thumbnail(200, 300)], format="JPEG", options={"quality": 90}, upload_to=articles_image_path, # MEDIA_ROOT(media)/articles/images ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) like_users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name="like_articles", blank=True) hashtags = models.ManyToManyField(Hashtag, blank=True) class Meta: ordering = ("-pk",) def __str__(self): return f"{self.id}번글 - {self.title}: {self.content}"
class Search(models.Model): # image = models.ImageField(blank=True) image = ProcessedImageField( # source='image', processors=[Thumbnail(500, 500)], format='JPEG', options={'quality': 90})
class Article(models.Model): title = models.CharField(max_length=150) content = models.TextField() # blank - 유효성 검사 시 # null - DB상의 컬럼의 Null image = models.ImageField(blank=True, upload_to="%y/%m/%d/") # 업로드 날짜별 저장 image_thumbnail = ImageSpecField( source='image', processors=[Thumbnail(200,300)], format='JPEG', options={'quality':90}, ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) # 게시글 좋아요 like_users = models.ManyToManyField( settings.AUTH_USER_MODEL, related_name='like_articles', blank=True) # 게시글에 좋아요 없는 유효성 검사 통과할 수 있도록 blank=True 걸어준다. recommend_users = models.ManyToManyField( settings.AUTH_USER_MODEL, related_name='recommend_articles', blank=True) # Article이 호출되었을 때 출력되는 내용 - magic method def __str__(self): return f'{self.pk}번째 글, {self.title}-{self.content}'
class Board(models.Model): title = models.CharField(max_length=20) content = models.TextField() updated = models.DateTimeField(auto_now=True) created = models.DateTimeField(auto_now_add=True) # # ResizeToFill Ver.1 # image = ProcessedImageField( # upload_to = "boards/images_rtf", # processors = [ResizeToFill(600,500)], # format = "JPEG", # options = { # "quality": 85 # } # ) # Thumbnail Ver.1 (원본 X, 썸네일 O) # Thumbnail size 도 바꿔가면서 실습해보기 # image = ProcessedImageField( # upload_to = "boards/thumbnail", # processors = [Thumbnail(700, 700)], # format = "JPEG", # options = { # "quality": 90 # } # ) # thumbnail 원본 저장하고 썸네일은 캐쉬형태로 Ver.2 # 원본 저장 됨 / thumbnail은 CACHE로 필요할때 만들어서 저장. image = models.ImageField(blank=True, upload_to="boards/%Y/%m/%d") image_thumbnail = ImageSpecField(source='image', processors=[Thumbnail(550, 550)], format="JPEG", options={"quality": 90})
class User(AbstractUser): name = models.CharField(max_length=200) GENDER_CHOICES = [(0, 'Male'), (1, 'Female')] gender = models.IntegerField(default=True, choices=GENDER_CHOICES) # 희망 습도 desired_humidity = models.IntegerField(default=40) # 가습기 자동 온오프 - true / 사용자 조작 - false auto_setting = models.BooleanField(default=True) # 가습기 사용자 조작 on / off humidifier_on_off = models.BooleanField(default=False) # 무음모드 silent_mode = models.BooleanField(default=False) birth_date = models.DateField(null=True) image = models.ImageField(default='/images/default_user.png', upload_to='profile') # 업로드 경로 설정 다시 해야함! media 디렉토리 image_thumbnail = ImageSpecField( source = 'image', processors = [Thumbnail(100,100)], format = 'JPEG', options = {'quality':60} ) friends = models.ManyToManyField('self') room = models.ForeignKey(Room, null=True, on_delete=models.CASCADE, related_name='members') current_state = models.IntegerField(default=1) # 1-아무것도 안함 2-공부중 3-휴식중, 4-일시정지 # 알림 소리 테마 theme = models.IntegerField(default=1)
class Article(models.Model): title = models.CharField(max_length=150) content = models.TextField() # blank = 유효성 검사시 # null = DB 상의 컬럼의 Null image = models.ImageField(blank=True, upload_to=articles_image_path) image_thumbnail = ImageSpecField(source='image', processors=[Thumbnail(200, 300)], format='JPEG', options={'quality': 90}) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) hits = models.PositiveIntegerField(default=0) like_users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='like_articles', blank=True) recommend_users = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='recommend_articles', blank=True) @property def click(self): self.hits += 1 self.save()
class Clients(TimeStampModel): """ Model that contains TMA clients logos and website link """ link = models.CharField(max_length=255, null=False, blank=False) client_logo = models.ImageField(upload_to='clients', null=False, blank=False) client_img = ImageSpecField(source='client_logo', processors=[Thumbnail(165, 127.14)], options={'quality': 100})
class Product(models.Model): user = models.CharField(max_length=20, verbose_name="작성자", help_text="작성자를 입력해 주세요.") title = models.CharField(max_length=100, verbose_name="제목", help_text="포스팅 제목을 입력해주세요. 최대 100자 내외.", validators=[len_validator]) content = models.TextField(verbose_name="내용") photo = models.ImageField(blank=True, upload_to='product/post/%Y/%m/%d') #방법 1 원본이 있고 원본을 통한 썸네일 처리 photo_thubnail = ImageSpecField(source="photo", processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 60}) user_agent = models.CharField(max_length=200, blank=True) created_at = models.DateTimeField(auto_now_add=True) update_at = models.DateTimeField(auto_now=True) class Meta: ordering = [ '-id' ] #id로 내림 차순 정렬을 기본으로 정렬하겠다. [안에 여러 조건을 줄 수는 있지만 1가지 조건을사용하는 것을 추천] def __str__(self): return self.title def get_absolute_url(self): return reverse('product:product_detail', args=[self.id])
class Post(models.Model): STATUS_CHOICES = (('d', 'Draft'), ('p', 'Published'), ('w', 'Withdrawn')) user = models.ForeignKey(settings.AUTH_USER_MODEL) title = models.CharField( max_length=100, help_text='please enter the post title. max length : 100 characters.') content = models.TextField() photo = ProcessedImageField(blank=True, upload_to='blog/post/%Y/%m/%d', processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 60}) tags = models.CharField(max_length=100, blank=True) lnglat = models.CharField(max_length=50, blank=True, validators=[lnglat_validator], help_text='longitude/latitude format insert') status = models.CharField(max_length=1, choices=STATUS_CHOICES) tag_set = models.ManyToManyField('Tag', blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: ordering = ['-id'] def __str__(self): return self.title def get_absolute_url(self): return reverse('blog:post_detail', args=[self.id])
class Lawyer(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL) name = models.CharField(max_length=30, help_text='한글성명을 입력해주세요.', verbose_name='성명(한글)') name_en = models.CharField(max_length=30, help_text='영문성명을 입력해주세요.', verbose_name='성명(영문)') email_address = models.EmailField(help_text='이메일주소를 입력해주세요.') address = models.CharField(max_length=100, help_text='사무실 주소를 입력해주세요.', blank=True) phone = models.CharField(blank=True, max_length=20, help_text='전화번호를 입력해주세요.') fax = models.CharField(max_length=50, blank=True, help_text='팩스번호를 입력해주세요.') unique_url = models.CharField(max_length=50, unique=True, help_text='주소에 사용될 영문자(대소문자구분)를 작성해주세요 (ex)영문성함, 사무소이름 등') profile_image = ProcessedImageField(blank=True, upload_to='lawyer/%Y/%m/%d', processors=[Thumbnail(300,400)], format='JPEG', options={'quality':70}) fields = models.CharField(blank=True, max_length=50, help_text='관련업무분야를 선택해주세요.') intro = models.TextField(blank=True, help_text='"000변호사의 주된 업무분야는 xx,xx,xx 입니다. 0변호사는 ~한 활동을 하고 있고 ---."와 같은 형식으로 입력해주세요.', verbose_name='소개') p_certificate = models.CharField(max_length=50, help_text='년도/자격을 작성해주세요. 예시)2004/변호사(대한민국)', verbose_name='자격취득') p_edu = models.TextField(blank=True, help_text='학력사항을 작성해주세요.', verbose_name='학력') p_story = models.TextField(blank=True, help_text='경력 사항을 작성해주세요.', verbose_name='경력') p_activity = models.TextField(blank=True, help_text='저서/활동을 작성해주세요.', verbose_name='저서/활동') p_prize = models.TextField(blank=True, help_text='수상내역을 작성해주세요.', verbose_name='수상') def __str__(self): return self.name def get_absolute_url(self): return reverse('lawyer:lawyer_detail', args=[self.unique_url])
class Board(models.Model): idx = models.AutoField(primary_key=True) writer = models.CharField(null=False, max_length=50) title = models.CharField(null=False, max_length=120) hit = models.IntegerField(default=0) content = models.TextField(null=False) post_date = models.DateTimeField(default=datetime.now, blank=True) filename = models.CharField(null=True, blank=True, default="", max_length=500) filesize = models.IntegerField(default=0) down = models.IntegerField(default=0) ratings_up = models.IntegerField(default=0) ratings_down = models.IntegerField(default=0) rating = models.IntegerField(default=0) win_score = models.IntegerField(default=0) is_finished = models.BooleanField(default=False) image_thumbnail = ProcessedImageField(upload_to='media/thumbnail', processors=[Thumbnail(100, 100)], format='JPEG', options={'quality': 60}, null=True) def hit_up(self): self.hit += 1 def down_up(self): self.down += 1 def rate_up(self): self.ratings_up += 1 def rate_down(self): self.ratings_down += 1
class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) nickname = models.CharField(max_length=200, blank=True) # photo = models.ImageField(upload_to="profile/image/", default="profile/image/basic.jpg") photo = ProcessedImageField( upload_to="profile/image", default="profile/image/basic.jpg", processors=[ ResizeToFit(width=960, upscale=False), Thumbnail(100, 100) ], options={'quality': 90}, ) point = models.IntegerField(blank=True, default="0") grade = models.IntegerField(blank=True, default="0") myIntro = models.CharField(max_length=200, blank=True) Tier = models.CharField(max_length=20, blank=True) username_info = models.CharField(max_length=150, unique=True, default="") email_info = models.EmailField(unique=True, null=False, default="") password_info = models.CharField(max_length=128, default="") name = models.CharField(max_length=150, null=False, default="") number = models.CharField(max_length=12, unique=True, default="010", null=False)
class Article(models.Model): title = models.CharField(max_length=20) content = models.TextField() # image = models.ImageField(blank=True) # image_thumbnail = ImageSpecField( # 처음엔 원본만 만들어주고 썸네일 관련해서 호출할 때만 썸네일로 저장된다. # source='image', # 원본 ImageField 이름 (upload_to 대신 source를 사용) # processors=[Thumbnail(200, 300)], # format='JPEG', # options={'quality': 90}, # ) image = ProcessedImageField( # ProcessedImageField 에 인자로 들어가 있는 값들은 migrations 이후에 # 추가되거나 수정되더라도 makemigrations 를 하지 않아도 된다. processors=[Thumbnail(200, 300)], # processors : 처리할 작업 목록 format='JPEG', # 저장 포맷 (JPEG가 퀄리티를 낮췄을 때 이미지가 덜 깨진다.) options={'quality': 90}, # 추가 옵션들 upload_to='articles/images', # 저장 위치(MEDIA_ROOT/articles/images) ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.title def get_absolute_url(self): # return f'/articles/{self.pk}/' # args는 리스트로 넣는다. # kwargs는 딕셔너리로 넣는다. # return reverse('articles:detail', args=[self.pk]) return reverse('articles:detail', kwargs={'article_pk': self.pk }) # 딕셔너리의 key는 views.py의 detail 함수의 pk이다.
class Profile(models.Model): SERVER_CHOICES = ( ('울프', '울프'), ('만돌린', '만돌린'), ('하프', '하프'), ('류트', '류트'), ) RACE_CHOICES = ( ('인간', '인간'), ('엘프', '엘프'), ('자이언트', '자이언트'), ) SKILL_CHOICES =( ('근접 전투','근접 전투'), ('랜스','랜스'), ('궁술','궁술'), ('마법','마법'), ('격투술','격투술'), ('연금술','연금술'), ('올라운더','올라운더') ) server = models.CharField(max_length=3, choices=SERVER_CHOICES) user = models.OneToOneField(settings.AUTH_USER_MODEL) userid = models.CharField(max_length=20) race = models.CharField(max_length=4, choices=RACE_CHOICES) skill = models.CharField(max_length=50, choices=SKILL_CHOICES) context = models.CharField(max_length=300, blank=True) image = ProcessedImageField( processors=[Thumbnail(350, 350)], upload_to='userimage/%Y/%m/%d', format='JPEG', options={'quality': 80}, blank=True)
class Editions(models.Model): publish = models.BooleanField(default=False) year = models.CharField(max_length=4) month = models.CharField(max_length=2) edition = models.PositiveIntegerField(primary_key=True) img = models.ImageField(upload_to=main_upload_directory, blank=False) calender = models.ImageField(upload_to=calender_upload_directory, blank=True, null=True) calender_thumbnail = ImageSpecField( source = 'calender', processors = [Thumbnail(362, 512)], format = 'JPEG', options = {'quality' : 60}) def __str__(self): return "edition " + str(self.edition) def json_edition(self): return {'edition_year': self.year, 'edition_number': str(self.edition), 'edition_month': self.month, 'edition_cover': base_url + self.img.url} def json_calender(self): return {'year' : self.year, 'month' : self.month, 'calender' : base_url + self.calender.url, 'calender_thumbnail' : base_url + self.calender_thumbnail.url}
class Article(models.Model): title = models.CharField(max_length=150) content = models.TextField() # blank = 유효성 검사시 # null = DB 상의 컬럼의 Null image = models.ImageField(blank=True, upload_to=articles_image_path) image_thumbnail = ImageSpecField( source='image', processors=[Thumbnail(200, 300)], format='JPEG', options={'quality':90} ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) # related_name 가 필요한 이유 # like_users.like_articles.all()로 데이터를 가져오기 위해 like_users = models.ManyToManyField( settings.AUTH_USER_MODEL, related_name='like_articles', blank=True ) recommand_users = models.ManyToManyField( settings.AUTH_USER_MODEL, related_name='recommand_articles', blank=True ) def __str__(self): return f'{self.pk}번째 글, {self.title}-{self.content}'
class ArticleImages(models.Model): article = models.ForeignKey(Article, on_delete=models.CASCADE) image = models.ImageField(blank=True) image_thumbnail = ImageSpecField(source='image', processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 90})
class Article(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) like_user = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='like_articles') # image = models.ImageField(upload_to="%Y/%m/%d/",blank=True) image = ProcessedImageField(blank=True, format="JPEG", processors=[Thumbnail(614, 614)], upload_to="%Y/%m/%d/") image_thumbnail = ImageSpecField(source="image", processors=[ResizeToFill(614, 614)], format='JPEG') # image = ProcessedImageField( # blank=True, # format="JPEG", # processors=[Thumbnail(614,614),ResizeToFill(614,614)], # upload_to="%Y/%m/%d/" # ) content = models.TextField() created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.content
class Article(models.Model): title = models.CharField(max_length=20) content = models.TextField() # image = models.ImageField(blank=True) # image_thumbnail = ImageSpecField( # source='image', # 원본 ImageField 이름 # processors=[Thumbnail(200,300)], # format='JPEG', # options={'quality': 90}, # ) image = ProcessedImageField( # ProcessedImageField 에 인자로 들어가 있는 값들은 migrations 이후에 # 추가되거나 수정되더라도 makemigrations 를 하지 않아도 된다. processors=[Thumbnail(200, 300)], # 처리할 작업 목록 format='JPEG', # 저장 포맷 options={'quality': 90}, # 추가 옵션들 upload_to='articles/images', # 저장 위치 (MEDIA_ROOT/article/images) ) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) def __str__(self): return self.title def get_absolute_url(self): # return f'/articles/{self.pk}/' # return reverse('articles:detail', args=[self.pk]) # /articles/10/ return reverse('articles:detail', kwargs={'article_pk': self.pk}) # /articles/10/
class Post(models.Model): SUBJECTS_CHOICES = ( ('R1', 'Rails'), ('R2', 'Ruby'), ('H', 'HTML'), ('J', 'JS'), ('P', 'PY'), ('O', 'Other'), ) user = models.ForeignKey(settings.AUTH_USER_MODEL) title = models.CharField(max_length=100) content = models.TextField(validators=[content_validator]) photo = ProcessedImageField(blank=True, upload_to='board/post/%Y/%m/%d', processors=[Thumbnail(300, 300)], format='JPEG', options={'quality': 60}) user_agent = models.CharField(max_length=200) tags = models.CharField(max_length=100, blank=True) subjects = models.CharField(max_length=1, choices=SUBJECTS_CHOICES) tag_set = models.ManyToManyField('Tag', blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: ordering = ['-id'] def __unicode__(self): return self.title def get_absolute_url(self): return reverse('board:post_detail', args=[self.id])
class Partner(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) name = models.CharField( max_length=50, verbose_name="업체이름", ) contact = models.CharField( max_length=50, verbose_name="연락처", ) address = models.CharField(max_length=100, verbose_name="주소") description = models.TextField(verbose_name="상세 소개") is_active = models.BooleanField(default=False, ) category = models.CharField( max_length=20, choices=CATEGORIES, default=KOREA, verbose_name="카테고리", ) image_thumbnail = ProcessedImageField( upload_to='partner/menu', processors=[Thumbnail(120, 120)], format='jPEG', options={'qulity': 80}, verbose_name="대표이미지", ) def __str__(self): return self.name
class Post(models.Model): author = models.CharField(max_length=20, default=get_random_name) title = models.CharField(max_length=30, verbose_name='제목') text = models.TextField(max_length=300, verbose_name='내용', blank=True, null=True) photo = models.ImageField(max_length=300, verbose_name='이미지', upload_to='upload_img', blank=True) photo_thumbnail = ImageSpecField( source='photo', # 원본 ImageField 명 processors=[Thumbnail(64, 64)], # 처리할 작업목록 format='JPEG', # 최종 저장 포맷 options={'quality': 100} # 저장 옵션 ) created_at = models.DateTimeField(default=timezone.now) published_at = models.DateTimeField(blank=True, null=True) def publish(self): self.published_date = timezone.now() self.save() def get_absolute_url(self): return reverse('post_detail', args=[self.pk]) def __str__(self): return self.title