class Announcement(models.Model): title = models.CharField(max_length=200, null=True) writer = models.CharField(max_length=200, null=True) content = models.TextField(null=True) announcement_img = DefaultStaticImageField( upload_to='announcement_img/', blank=True, default_image_path='images/default_announcement_img.png') announcement_file = DefaultStaticImageField( upload_to='announcement_file/', blank=True, default_image_path='files/dummy.txt') pub_date = models.DateTimeField('Date published', null=True)
class VolOpp(models.Model): orgname = models.CharField('Organization Name', max_length=120, blank=True) vol_title = models.CharField('Title', max_length=200, blank=False) vol_description = models.TextField('Description', blank=False) vol_location = models.CharField('Location', max_length=200, blank=False) vol_date = models.DateTimeField('Date', blank=False) org_phone = models.CharField('Contact Phone', max_length=20, blank=True) age_requirements = models.IntegerField('Age Requirements', blank=False) points = models.IntegerField('Points Worth', blank=False) vol_photo = DefaultStaticImageField('Upload Image',upload_to='voloppimgs/', blank=True, default_image_path='/voloppimgs/default.png') FILTERS = ( ('animal', 'Animals'), ('artmusic','Arts & Music'), ('edu', 'Education'), ('env', 'Environment'), ('health', 'Health & Medicine'), ('justice', 'Jusitce & Legal'), ('others', 'Others') ) vol_filters = MultiSelectField('Filters', choices = FILTERS, default="") def __str__(self): return self.name
class MyProfile(models.Model): name = models.CharField(max_length = 100) # first_name = models.CharField(max_length=12, blank=True) last_name = models.CharField(max_length=12, blank=True) # email = models.EmailField(max_length=150) # unique email confirmations # email = models.EmailField(max_length=150,unique=True) user = models.OneToOneField(to=User, on_delete=models.CASCADE) age = models.IntegerField(default=18, validators=[MinValueValidator(18)]) address = models.TextField(null=True, blank=True) status = models.CharField(max_length=20, default="single", choices=(("single","single"), ("married","married"), ("widow","widow"), ("seprated","seprated"), ("commited","commited"))) gender = models.CharField(max_length=20, default="female", choices=(("male","male"), ("female","female"))) phone_no = models.CharField(validators=[RegexValidator("^0?[5-9]{1}\d{9}$")], max_length=15, null=True, blank=True) description = models.TextField(null=True, blank=True) pic = DefaultStaticImageField(upload_to = "Download\\",blank=True, default='Download/un.jpg') # profile signup add cr_date = models.DateTimeField(auto_now_add=True) signup_confirmation = models.BooleanField(default=False) def __str__(self): return "%s" % self.name
class UserProfile(models.Model): user = models.OneToOneField(User) picture = DefaultStaticImageField(blank=True, default_image_path='default.png') def __str__(self): return self.user.username
class submit_form(models.Model): title=models.CharField(max_length=200,null=True) writer=models.CharField(max_length=200,null=True) pub_date=models.DateTimeField('Date published',null=True) body=models.TextField(null=True) attachment=DefaultStaticImageField(upload_to='submit_file/', null=True, blank=True, default_image_path='files/dummy.txt') submit=models.OneToOneField(Post,on_delete=models.CASCADE, null=True)
class User(AbstractUser): """ 연결된 모델 """ # HashTags 1:N # Contest N:M # 구현해야 할 목록 # 뱃지 이벤트들 구현해야함 .. """ 사용자 + 포트폴리오 모델 """ name = models.CharField(max_length=20) # 이름 image = DefaultStaticImageField(upload_to="images/", blank=True) # 프로필 사진 phone_number = models.CharField(max_length=20) # 전화번호 email = models.CharField(max_length=30) # 이메일 major = models.CharField(max_length=20) # 전공 university = models.CharField(max_length=40) # 학교 description = models.CharField(max_length=40) # 한 마디 hit_count = models.PositiveIntegerField(default=0) # 조회수 계산값 def __str__(self): return self.name # 유저에 대한 포트폴리오 조회수 카운트 반환 @property def update_hitcount(self): self.hit_count = self.hit_count + 1 self.save() return self.hit_count
class Profile(AbstractUser): start_year = models.CharField(max_length=200, null=True) sex = models.CharField(max_length=5, null=True) profile_img = DefaultStaticImageField( upload_to='profile_img/', blank=True, default_image_path='images/default_profile_img.png')
class Post(models.Model): title=models.CharField(max_length=200,null=True) writer = models.CharField(max_length=200,null=True) pub_date = models.DateTimeField('Date published',null=True) body = models.TextField(null=True) user = models.ManyToManyField(User, blank=True, related_name= 'scrapped') status=models.CharField(default='ready',max_length=200) hashtag = models.ManyToManyField(Hashtag, related_name="post_tag") approved_id=models.CharField(null=True,max_length=200) s_flag=models.BooleanField(default=False) attached_img=DefaultStaticImageField(upload_to='attached_img/', blank=True, default_image_path='images/default_mission_img.png') attached_file=DefaultStaticImageField(upload_to='attached_file/', blank=True, default_image_path='files/dummy.txt') deposit=models.IntegerField(default=0) def __str__(self): return self.title
class Brand(models.Model): brd_name = models.CharField(max_length=100) brd_img = DefaultStaticImageField( upload_to='brand_img/', blank=True, default_image_path='images/default_goorm_img.png') def __str__(self): return self.brd_name
class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) position = models.CharField(max_length=150) location = models.CharField(max_length=30) e_mail = models.EmailField(null=True, blank=True, default='') phone = models.CharField(max_length=20, blank=True) web_sites = models.URLField(max_length=200, blank=True) common_information = models.TextField(max_length=500, blank=True) profile_image = DefaultStaticImageField( blank=True, null=True, default_image_path='img/blog/unnamed.jpg')
class SharingBoard(LandBoard): land_img = DefaultStaticImageField( upload_to='land_img/', blank=True, default_image_path='images/default_land_img.png') writer = models.ForeignKey( Profile, on_delete=models.CASCADE, related_name='profile_sb') #작성자 - 땅게시판 (1:N) 관계설정. is_free = models.BooleanField(default=True) #무료여부 amount_period = models.CharField(max_length=30) #지불 기간 (연당, 월당, 일당) amount = models.IntegerField(null=True, blank=True) #금액 choice_land = models.ForeignKey(Land, on_delete=models.CASCADE)
class Profile(AbstractUser): nickname = models.CharField(max_length=200, null=True) # - nickname sns_id = models.CharField(max_length=200, null=True) # - SNS_ID introduce = models.TextField(null=True) # - 자기소개란 score = models.IntegerField(null=True) # - score profile_img = DefaultStaticImageField( upload_to='profile_img/', blank=True, default_image_path='images/default_profile_img.png') def __str__(self): return self.username
class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) profile_img = DefaultStaticImageField( upload_to='profile_imgs', default_image_path='profile_imgs/default_profile_img.jpeg') profile_banner = DefaultStaticImageField( upload_to='profile_imgs', default_image_path='profile_imgs/default_profile_banner.jpeg') bio_short = models.TextField(max_length=100, blank=True) bio = models.TextField(max_length=500, blank=True) location = models.CharField(max_length=30, blank=True) show_location = models.BooleanField(default=True) show_email = models.BooleanField(default=False) birth_date = models.DateField(null=True, blank=True) following = models.ManyToManyField( User, related_name='following', blank=True) # These users I am following followers = models.ManyToManyField( User, related_name='is_following', blank=True) # These users are following me objects = Profile_Manager() # for badges is_verified = models.BooleanField(default=False) is_pro = models.BooleanField(default=False) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.profile.save()
class B_Blog(models.Model): title = models.CharField(max_length=200) writer = models.CharField(max_length=200) body = models.TextField() pub_date = models.DateTimeField('Date published', null=True) user = models.ManyToManyField(User, blank=True, related_name='user') dislike = models.ManyToManyField(User, blank=True, related_name='dislike') hashtag = models.ManyToManyField(Hashtag, related_name="freeboard_tag") attached_img = DefaultStaticImageField( upload_to='attached_img/', blank=True, default_image_path='images/default_free_img.png') attached_file = DefaultStaticImageField( upload_to='attached_file/', blank=True, default_image_path='files/dummy.txt') @property def total_likes(self): return self.user.count() #likes 컬럼의 값의 갯수를 센다 @property def total_dislikes(self): return self.dislike.count() #likes 컬럼의 값의 갯수를 센다
class Profile(models.Model): user=models.OneToOneField(User,on_delete=models.CASCADE, null=True) university=models.CharField(max_length=200,null=True) department=models.CharField(max_length=200,null=True) name=models.CharField(max_length=200,null=True) hashtag=models.ManyToManyField(Hashtag, related_name="my_tag") introduction=models.TextField(null=True) email=models.CharField(max_length=200,null=True,unique=True) approval=models.BooleanField(default=False) profile_id=models.CharField(unique=True,max_length=200,null=True) profile_img=DefaultStaticImageField(upload_to='profile_img/', blank=True, default_image_path='images/default_profile_img.png') money=models.IntegerField(default=0) connector=models.IntegerField(null=True) mission_count=models.IntegerField(default=0) def __str__(self): return str(self.user)
class User(AbstractBaseUser, PermissionsMixin): name = models.CharField(max_length=30) email = models.EmailField(max_length=40, unique=True) cell_number = models.IntegerField(default=None, null=True) profile_picture = DefaultStaticImageField( upload_to='user_images', null=True, blank=True, default_image_path='img/anonymous-user.png') is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) is_admin = models.BooleanField(default=False) USERNAME_FIELD = 'email' objects = UserManager() def __str__(self): return self.name
class Tobacco(models.Model): brand = models.ForeignKey(Brand, on_delete=models.CASCADE, related_name='tobacco') name = models.CharField(max_length=50) price = models.IntegerField(blank=True) # rel_date = models.CharField(max_length=100) nicotine = models.FloatField() TAR = models.FloatField() feel_of_hit = models.CharField(max_length=10) score = models.FloatField(default=0) isMenthol = models.BooleanField(default=False) img = DefaultStaticImageField( upload_to='goorm_img/', blank=True, default_image_path='images/default_goorm_img.png') def __str__(self): return self.name
class Trip(models.Model): destination = models.CharField(max_length=255) start_date = models.DateField() end_date = models.DateField() description = models.TextField() image = DefaultStaticImageField( upload_to="trip_image", blank=True, default_image_path='app_1/images/noimg2.png') # image = models.ImageField(upload_to="trip_image", default = 'app_1/images/noimg.png') planner = models.ForeignKey(User, related_name="planned_trips", on_delete=models.CASCADE) attendees = models.ManyToManyField(User, related_name="attending_trips") created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) objects = DataManager() def __repr__(self): return f"<Trip object: {self.destination} ({self.id})>"
class Film(models.Model): ACTION = 'AC' ADVENTURE = 'AD' COMEDY = 'CM' CRIME = 'CR' DRAMA = 'DR' HISTORICAL = 'HS' HORROR ='HR' MUSICALS = 'MC' SCIENCE = 'SC' WAR = 'WR' WESTERNS = 'WN' GENRES_CHOICES = ( (ACTION, 'Action'), (ADVENTURE, 'Adventure'), (COMEDY, 'Comedy'), (CRIME, 'Crime'), (DRAMA, 'Drama'), (HISTORICAL, 'Historical'), (HORROR, 'Horror'), (MUSICALS, 'Musicals'), (SCIENCE, 'Science'), (WAR, 'War'), (WESTERNS, 'Westerns'), ) title = models.CharField(max_length=200) picture = DefaultStaticImageField(upload_to='pictures/%Y/%m/%d', blank=True, default_image_path=settings.DEFAULT_IMAGE_PATH) genre = models.CharField(choices=GENRES_CHOICES, max_length=2) description = models.TextField() release_year = models.DateField() period_from = models.DateField() period_to = models.DateField() created_on = models.DateTimeField(auto_now_add=True) updated_on = models.DateTimeField(auto_now=True) def __str__(self): return f"Film '{self.title}'"
class UserProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='profile', null=True, on_delete=models.SET_NULL) #1 following = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name='followed_by') #2 profile_image = DefaultStaticImageField( upload_to=upload_location, null=True, blank=True, default_image_path='images/dp.jpg', width_field="width_profilefield", height_field="height_profilefield") # images stuff height_profilefield = models.IntegerField(default=0, null=True, blank=True) width_profilefield = models.IntegerField(default=0, null=True, blank=True) cover_image = DefaultStaticImageField( upload_to=upload_location, null=True, blank=True, default_image_path='images/cover.png', width_field="width_coverfield", height_field="height_coverfield") # images stuff height_coverfield = models.IntegerField(default=0, null=True, blank=True) width_coverfield = models.IntegerField(default=0, null=True, blank=True) dob = models.DateField(null=True, blank=True) GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ('U', 'Unspecified'), ) gender = models.CharField(max_length=1, choices=GENDER_CHOICES, null=True) city = models.CharField(max_length=140, null=True, blank=True) country = CountryField(blank=True, null=True) status = models.CharField(max_length=200, null=True, blank=True) phone_number = models.CharField( max_length=10, validators=[RegexValidator(r'^\d{1,10}$'), MinLengthValidator(10)], null=True, blank=True) facebook = models.URLField(null=True, blank=True) twitter = models.URLField(null=True, blank=True) instagram = models.URLField(null=True, blank=True) objects = UserProfileManager() # UserProfile.objects.all() #5 def __str__(self): return str(self.user) def __sts__(self): return str(self.following.all().count()) #3 def get_profileurl(self): return profile_image def get_following(self): #8 users = self.following.all( ) # User.objects.all().exclude(username = self.user.username) return users.exclude(username=self.user.username) def get_follow_url(self): return reverse_lazy("profiles:follow", kwargs={"username": self.user.username}) def get_absolute_url(self): return reverse_lazy("profiles:detail", kwargs={"username": self.user.username})
class Picture(models.Model): tmp_img=DefaultStaticImageField(upload_to='tmp_img/', blank=True, default_image_path='images/default_profile_img.png')
class DefaultImg(models.Model): image = DefaultStaticImageField(upload_to='default_img/', blank=True, default_image_path='images/default_profile_img.png')
class User(PolymorphicModel, AbstractUser, DeletedFlagMixin, TimeStampedModel): TYPE_WPS = 'wps' TYPE_CHOICES = ((TYPE_WPS, '웹 프로그래밍 스쿨'), ) first_name = None last_name = None name = models.CharField('이름', max_length=20, blank=True) type = models.CharField('분류', choices=TYPE_CHOICES, max_length=20) img_profile = DefaultStaticImageField( '프로필 이미지', upload_to='user', default_image_path='images/profile.jpg', blank=True) nickname = models.CharField('닉네임', max_length=20, unique=True, blank=True, null=True) email = models.EmailField('이메일', unique=True) phone_number = PhoneNumberField('전화번호', blank=True) # Deleted deleted_email = models.EmailField('삭제된 유저의 이메일', blank=True) deleted_username = models.CharField('삭제된 유저의 username', max_length=150, blank=True) REQUIRED_FIELDS = ('email', ) objects = UserManager() class Meta: verbose_name = '사용자' verbose_name_plural = f'{verbose_name} 목록' def __str__(self): return self.name def save(self, *args, **kwargs): super().save(*args, **kwargs) def perform_delete(self): def get_deleted_username(num): return f'deleted_{num:05d}' self.deleted_username = self.username self.deleted_email = self.email # is_deleted = True로 저장하기 전에, deleted_숫자 의 username을 갖도록 함 last_deleted_user = User._base_manager.filter( is_deleted=True).order_by('username').last() if last_deleted_user: number = int(last_deleted_user.username.rsplit('_', 1)[-1]) + 1 else: number = 0 deleted_name = get_deleted_username(number) self.username = deleted_name self.email = None self.nickname = None # 만약 계산한 deleted_name이 이미 존재할 경우, 모든 삭제된 User들의 deleted_name을 다시 재설정 if User._base_manager.filter(username=deleted_name).exists(): index = 0 for user in User._base_manager.filter( is_deleted=True).order_by('pk'): user.username = get_deleted_username(index) user.save() index += 1 self.username = get_deleted_username(index)
class User(AbstractUser, TimeStampedModel, DeleteModel): TYPE_KAKAO, TYPE_FACEBOOK, TYPE_GOOGLE, TYPE_EMAIL = 'kakao', 'facebook', 'google', 'email' TYPE_CHOICES = ( (TYPE_KAKAO, '카카오'), (TYPE_FACEBOOK, '페이스북'), (TYPE_GOOGLE, '구글'), (TYPE_EMAIL, '이메일'), ) first_name = None last_name = None img_profile = DefaultStaticImageField( '프로필 이미지', upload_to='user', default_image_path='images/profile.jpg', blank=True) name = models.CharField('이름', max_length=20, blank=True) nickname = models.CharField('닉네임', max_length=20, blank=True, null=True) type = models.CharField('유형', max_length=10, choices=TYPE_CHOICES, default=TYPE_EMAIL) email = models.EmailField('이메일', unique=True, null=True) phone_number = PhoneNumberField('전화번호', blank=True) # Deleted deleted_email = models.EmailField('삭제된 유저의 이메일', blank=True) deleted_username = models.CharField('삭제된 유저의 username', max_length=150, blank=True) REQUIRED_FIELDS = ('email', ) objects = UserManager() def __str__(self): return f'{self.name} ({self.email}) (pk: {self.pk})' class Meta: verbose_name = '사용자' verbose_name_plural = f'{verbose_name} 목록' def save(self, *args, **kwargs): if self.type == self.TYPE_EMAIL and not self.is_deleted: self.username = self.email super().save(*args, **kwargs) def perform_delete(self): def get_deleted_username(num): return f'deleted_{num:05d}' self.deleted_username = self.username self.deleted_email = self.email # is_deleted = True로 저장하기 전에, deleted_숫자 의 username을 갖도록 함 last_deleted_user = User._base_manager.filter( is_deleted=True).order_by('username').last() if last_deleted_user: number = int(last_deleted_user.username.rsplit('_', 1)[-1]) + 1 else: number = 0 deleted_name = get_deleted_username(number) self.username = deleted_name self.email = None # 만약 계산한 deleted_name이 이미 존재할 경우, 모든 삭제된 User들의 deleted_name을 다시 재설정 if User._base_manager.filter(username=deleted_name).exists(): index = 0 for user in User._base_manager.filter( is_deleted=True).order_by('pk'): user.username = get_deleted_username(index) index += 1 self.username = get_deleted_username(index)