class PhotoOfTheDay(models.Model): title = models.CharField(max_length=100, default="") photographer = models.CharField(max_length=100, default="") img = models.ImageField(default='potd_default.jpg', upload_to='potd') photographer_url = models.URLField(max_length=100, default="", verbose_name="Photographer url") slug = AutoSlugField(populate_from='title') draft = models.BooleanField(default=False) published = models.DateTimeField(default=timezone.now, auto_now=False, auto_now_add=False) date_posted = models.DateTimeField(default=timezone.now) user = models.ForeignKey(User, on_delete=models.CASCADE, default="") feature_potd = models.BooleanField(default=False, verbose_name="Featured POTD") featured_as_potd = models.BooleanField(default=False, verbose_name="Has Been POTD") class Meta: verbose_name_plural = "Photo of the day" def save(self, *args, **kwargs): self.slug = slugify(self.title) super(PhotoOfTheDay, self).save(*args, **kwargs) def __str__(self): return self.title
class Gallery(models.Model): title = models.CharField(max_length=30) slug = AutoSlugField(populate_from='title', default="needs-slug", unique=True) user = models.ForeignKey(User, on_delete=models.CASCADE, default=1) cover_photo = models.ForeignKey('Photo', on_delete=models.CASCADE, default=None, null=True) visible = models.BooleanField(default=True) MASONRY = 'MA' MUSEUM = 'MU' GALLERY_TYPE_CHOICES = [ (MASONRY, 'Masonry'), (MUSEUM, 'Museum'), ] type = models.CharField( max_length=2, choices=GALLERY_TYPE_CHOICES, default=MASONRY, ) def __str__(self): return self.title class Meta: verbose_name_plural = "Galleries"
class Category(models.Model): title = models.CharField(max_length=100) slugger = AutoSlugField( unique=True, populate_from="title", blank=True, null=True, )
class Chama(models.Model): DAILY = 'daily' WEEKLY = 'weekly' MONTHLY = 'monthly' YEARLY = 'yearly' CIRCLE_CHOICES = ( (DAILY, _('daily')), (WEEKLY, _('weekly')), (MONTHLY, _('monthly')), (YEARLY, _('yearly')), ) FREE = 'free' STARTER = 'starter' BRONZE = 'bronze' SILVER = 'silver' PLATINUM = 'platinum' PLAN_CHOICES = ( (FREE, _('free')), (STARTER, _('starter')), (BRONZE, _('bronze')), (SILVER, _('silver')), (PLATINUM, _('platinum')), ) creator = models.CharField(max_length=255) mobile_number = models.CharField(max_length=13) name = models.CharField(max_length=255) year_founded = models.CharField(max_length=255) maximum_members = models.CharField(max_length=255) description = models.CharField(max_length=255) contribution_intervals = models.CharField(max_length=255, choices=CIRCLE_CHOICES) total_contributions = models.CharField(max_length=255) saved_amounts = models.CharField(max_length=255) plan_package = models.CharField(max_length=255, choices=PLAN_CHOICES) twitter_link = models.CharField(max_length=255) facebook_link = models.CharField(max_length=255) slug = AutoSlugField(populate_from='name', unique=True) date = models.DateTimeField(auto_now_add=True) class Meta: ordering = ['-date'] verbose_name = _('chama') verbose_name_plural = _('chamas') def __str__(self): if six.PY3: return self.__unicode__() else: return self.__unicode__().encode('utf-8') def __unicode__(self): try: chamaa = self.name except ObjectDoesNotExist: chamaa = None return "{0}".format(chamaa)
class Migration(migrations.Migration): dependencies = [ ('events', '0004_rename_fields'), ] operations = [ migrations.AddField( model_name='event', name='slug', field=AutoSlugField(null=True, populate_from='title', unique_for_year='start'), ), migrations.RunPython(generate_slugs), migrations.AlterField( model_name='event', name='slug', field=AutoSlugField(populate_from='title', unique_for_year='start'), ), ]
class Gallery(models.Model): title = models.CharField(max_length=30) slug = AutoSlugField(populate_from='title', default="needs-slug") user = models.ForeignKey(User, on_delete=models.CASCADE, default=1) def __str__(self): return self.title class Meta: verbose_name_plural = "Galleries"
class Collection(HasLinkedSequenceMixin, models.Model): """Set of Activities (problems) for a module.""" name = fields.CharField(max_length=255) slug = AutoSlugField( populate_from='name', unique=True, db_index=True, help_text= "Add the slug for the collection. If field empty slug will be created automatically.", verbose_name='slug id') owner = models.ForeignKey(BridgeUser, on_delete=models.CASCADE) metadata = fields.CharField(max_length=255, blank=True, null=True) strict_forward = fields.BooleanField(default=True) updated_at = fields.DateTimeField(auto_now=True) class Meta: unique_together = ('owner', 'name') def __str__(self): return '<Collection: {}>'.format(self.name) def save(self, *args, **kwargs): """Extension cover method with logging.""" initial_id = self.id super().save(*args, **kwargs) tasks.sync_collection_engines.apply_async( kwargs={ 'collection_slug': self.slug, 'created_at': self.updated_at }, countdown=settings.CELERY_DELAY_SYNC_TASK, ) if initial_id: Log.objects.create(log_type=Log.ADMIN, action=Log.COLLECTION_UPDATED, data={'collection_id': self.id}) else: Log.objects.create(log_type=Log.ADMIN, action=Log.COLLECTION_CREATED, data={'collection_id': self.id}) def get_absolute_url(self): return reverse('module:collection-list') def get_launch_url(self, group): return "{}{}".format( settings.BRIDGE_HOST, reverse("lti:launch", kwargs={ 'collection_slug': self.slug, 'group_slug': group.slug }))
class Photo(models.Model): caption = models.TextField(default="") visible = models.BooleanField(default=True) galleries = models.ManyToManyField(Gallery) uploaded_at = models.DateTimeField(auto_now_add=True) title = models.CharField(max_length=50, default="Untitled") file = models.FileField(storage=PublicMediaStorage(), default="") slug = AutoSlugField(populate_from='title', default="needs-slug") user = models.ForeignKey(User, on_delete=models.CASCADE, default=1) def __str__(self): return self.title
class BookDetail(TimeStampedModel): book_name = models.CharField(max_length=30) auther_name = models.CharField(max_length=30) book_details = models.CharField(max_length=300) book_price = models.FloatField() book_image = models.ImageField(upload_to='picture') book_file = models.FileField(upload_to='picture') slug = AutoSlugField(populate_from='book_name', unique=True, blank=True, null=True)
class Post(models.Model): title = models.CharField(max_length=120) slug = AutoSlugField(populate_from='title') content = models.TextField() overview = models.CharField(max_length=60) timestamp = models.DateTimeField(auto_now=True) def get_absolute_url(self): return reverse('posts:post-detail', kwargs={'id': self.id}) def __str__(self): return self.title
class Feed(models.Model): objects = managers.FeedManager() name = models.CharField(max_length=120, blank=False, null=False) active = models.BooleanField(default=True) url = models.URLField( unique=True, validators=[validators.valid_feed_url], blank=False, help_text='Enter a RSS feed url or a twitter account URL.') last_time_crawled = models.DateTimeField(null=True) slug = AutoSlugField(populate_from='name') def __unicode__(self): return self.name def __str__(self): return self.name
class Book(models.Model): title = models.CharField(max_length=200) author = models.ForeignKey(Author, related_name ="books", max_length=200, blank=True, null=True, on_delete=models.SET_NULL) category = models.CharField(max_length=200, blank=True, null=True) description = models.TextField(max_length=1000) created_at = models.DateField(auto_now_add=True) url = models.URLField(max_length=200) # slug = models.SlugField(unique=True) slug = AutoSlugField(unique=True, max_length=200, populate_from='title') # book_cover = models.ImageField(upload_to='books', blank=True, null=True) def __str__(self): return self.title def get_absolute_url(self): return reverse("book_detail", kwargs={"pk": self.pk}) #order booklist by most recent date added to database class Meta: ordering = ['-created_at']
class Book(models.Model): """ This class represents a book""" title = models.CharField(max_length=200, null=True, blank=True) slugger = AutoSlugField(unique=True, populate_from="title", blank=True, null=True) author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True) book_urls = models.URLField(max_length=150, null=True) book_description = models.CharField(max_length=5000, null=True, blank=True) date_added = models.DateField('Date Added', auto_now_add=True) book_image = models.ImageField(upload_to="book_image", blank="true") Favorited_by_user = models.ManyToManyField(to=User, related_name='favorites') categories = models.ManyToManyField(to=Category, related_name='books') class Meta: ordering = ['-date_added'] def __str__(self): return self.title
class Post(models.Model): STATUS_CHOICE = ( ('draft', 'Draft'), ('published', 'Published'), ) title = models.CharField(max_length=250) slug = AutoSlugField(populate_from='title') author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts') body = models.TextField() created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) published = models.DateTimeField(default=timezone.now) status = models.CharField(max_length=10, choices=STATUS_CHOICE, default='draft') tags = TaggableManager() class Meta: ordering = ['-published'] def __str__(self): return self.title def get_absolute_url(self): return reverse('blog:post_detail', args=self.slug)
class Book(models.Model): title = models.CharField(max_length=100) author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True) book_url = models.URLField(max_length=150, blank=True, null=True) book_description = models.CharField(max_length=5000, blank=True, null=True) date_added = models.DateTimeField('date added', auto_now=True) category = models.ForeignKey('Category', on_delete=models.SET_NULL, null=True) #book_image = models.ImageField(upload_to=) #add favorited #TODO slugger = AutoSlugField( unique=True, populate_from="title", blank=True, null=True, ) class Meta: ordering = ["-date_added"] def __str__(self): return self.title
class Event(models.Model): title = models.CharField(max_length=100, help_text="100 characters or fewer.") slug = AutoSlugField(populate_from='title', unique_for_year='start') tags = TaggableManager(blank=True) description = MarkdownField(rendered_field='description_rendered', validator=VALIDATOR_CLASSY) description_rendered = RenderedMarkdownField() url = models.URLField(blank=True) location = models.CharField(max_length=200) address = models.TextField(blank=True) start = models.DateField() start_time = models.TimeField(null=True, blank=True, help_text="Time is optional.") end = models.DateField(null=True, blank=True, help_text="End date and time are optional.") end_time = models.TimeField(null=True, blank=True, help_text="End date and time are optional.") image = VersatileImageField(upload_to='events', blank=True, null=True, ppoi_field='image_ppoi') image_ppoi = PPOIField() created = models.DateTimeField(auto_now_add=True, verbose_name="date created") modified = models.DateTimeField(auto_now=True, verbose_name="date modified") class Meta: ordering = ["start"] def __str__(self): return self.title def get_absolute_url(self): return reverse('events:detail', kwargs={ 'year': self.start.year, 'slug': self.slug }) @property def is_ended(self): if self.end: end = datetime.combine(self.end, self.end_time) if self.end_time else\ datetime.combine(self.end, datetime.min.time(), tzinfo=utc) else: end = datetime.combine( self.start, self.end_time) if self.end_time else (self.start + timedelta(days=1)) return end < now() @cached_property def structured_data(self): url = settings.SITE_URL + self.get_absolute_url() data = { '@type': 'Event', 'name': self.title, 'description': self.description or Truncator(strip_tags(self.description_rendered)).chars(200), 'startDate': self.start.strftime('%Y-%m-%d'), 'url': url, 'mainEntityOfPage': { '@type': 'WebPage', '@id': url }, } if self.end: data['endDate'] = self.end.strftime('%Y-%m-%d') if self.location: data['location'] = { '@type': 'Place', 'name': self.location, 'address': self.address or self.location, } if self.image: data['image'] = { '@type': 'ImageObject', 'url': self.image.url, 'height': self.image.height, 'width': self.image.width } return data
class plan_packages(models.Model): FREE = 'free' STARTER = 'starter' BRONZE = 'bronze' SILVER = 'silver' PLATINUM = 'platinum' PLAN_CHOICES = ( (FREE, _('free')), (STARTER, _('starter')), (BRONZE, _('bronze')), (SILVER, _('silver')), (PLATINUM, _('platinum')), ) name = models.CharField(max_length=20, choices=PLAN_CHOICES) chargable = models.BooleanField(default=True) charges = models.DecimalField(default=0.00, max_digits=8, decimal_places=2) maximum_users = models.IntegerField(default=5) bulk_emails = models.IntegerField(default=0) bulk_sms = models.IntegerField(default=0) slug = AutoSlugField(populate_from='plan_package', unique=True) date = models.DateTimeField(auto_now_add=True) class Meta: ordering = ['-date'] verbose_name = _('plan') verbose_name_plural = _('plans') def __str__(self): if six.PY3: return self.__unicode__() else: return self.__unicode__().encode('utf-8') def __unicode__(self): try: plan = self.name except ObjectDoesNotExist: plan = None return "{0}".format(plan) @property def persistent_id(self): return '{0}/{1}'.format(self.model_label(), self.id) @classmethod def model_label(cls): """ Returns an identifier for this Django model class This is just the standard "<app_label>.<model_name" form. """ return '{0}.{1}'.format(cls._meta.app_label, cls._meta.model_name) @classmethod def from_persistent_id(cls, persistent_id): """ :param persistent_id: :return: Loads a plan from its persistent id:: plan == plan_packages.from_persistent_id(plan_packages.persistent_id) """ plan = None try: model_label, plan_packages_id = persistent_id.rsplit('/', 1) app_label, model_name = model_label.split('.') plan_cls = apps.get_model(app_label, model_name) if issubclass(plan_cls, plan_packages): plan = plan_cls.objects.filter( id=int(plan_packages_id)).first() except (ValueError, LookupError): pass return "{0}".format(plan)
class Article(models.Model): objects = managers.ArticleManager() created_at = models.DateTimeField(auto_now_add=True) crawled_at = models.DateTimeField(null=True) title = models.CharField(max_length=200, default='Detecting title', null=False, blank=False) feed = models.ForeignKey('Feed') slug = AutoSlugField(populate_from='url', slugify=slugify_article_url) url = models.URLField(db_index=True, unique=True, blank=False) preservation_state = models.CharField(max_length=11, choices=STATES.PRESERVATION.list(), blank=True) archiving_state = models.CharField(max_length=12, choices=STATES.ARCHIVE.list(), blank=True, null=True) def delete_tags(self): return [tag.delete() for tag in self.tags()] def tags(self): qs = list(NotFoundOnlyTag.objects.filter(article=self)) qs = qs + list(ReleaseDateTag.objects.filter(article=self)) qs = qs + list(PriorityTag.objects.filter(article=self)) return qs def resources_dir(self): return '/'.join([self.feed.slug, self.slug]) def resource_path(self, filename, resource_type=None, use_tdir=True, uniq_fn=True): resources_dir = self.resources_dir() if use_tdir: if resource_type != None: resources_dir += '/{}s'.format(resource_type) else: raise ValueError("Must set resource_type argument") if uniq_fn: ext = filename.split('.')[-1] fid = str(uuid4()) filename = "{}.{}".format(fid, ext) return "{path}/{fn}".format(path=resources_dir, fn=filename) def index_path(self): return self.resource_path('index.html', use_tdir=False, uniq_fn=False) def index_resource(self): return storage.open(self.index_path(), 'rb') def has_index_resource(self): return storage.exists(self.index_path()) def deletedir(self): return storage.deletedir(self.resources_dir()) def set_crawled(self): self.crawled_at = timezone.now() if not self.should_preserve: self.preservation_state = STATES.PRESERVATION.NO_PRESERVE elif self.preservation_state != STATES.PRESERVATION.STORED: self.preservation_state = STATES.PRESERVATION.PRESERVE return self def set_stored(self): self.preservation_state = STATES.PRESERVATION.STORED @property def preview_url(self): kwargs = { 'feed_slug': self.feed.slug, 'article_slug': self.slug, } path = reverse('store:preview_article', kwargs=kwargs) return utils.absurl(path) @property def serve_url(self): kwargs = { 'feed_slug': self.feed.slug, 'article_slug': self.slug, } path = reverse('store:serve_article', kwargs=kwargs) return utils.absurl(path) @property def source(self): return self.feed.name @property def should_preserve(self): prio = PriorityTag.objects.filter(article=self, value=True) if prio.count() > 0: return False rdtag = ReleaseDateTag.objects.filter(article=self, value__lte=timezone.now()) nftag = NotFoundOnlyTag.objects.filter(article=self, value=True) return rdtag.exists() or nftag.exists()
class Board(TimeStampedModel, HitCountMixin): class Meta: verbose_name = u'게시판' verbose_name_plural = u'게시판' ordering = ['-created'] author = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name='작성자', ) title = models.CharField(verbose_name=u'제목', max_length=256) content = summer_fields.SummernoteTextField(verbose_name=u'내용', blank=True) category = models.ForeignKey( 'Category', verbose_name='카테고리', on_delete=models.CASCADE, ) hit_count_generic = GenericRelation( HitCount, object_id_field='object_pk', related_query_name='hit_count_generic_relation') like_user_set = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True, related_name='like_user_set', through='Like') notice = models.BooleanField(default=False) slug = AutoSlugField(unique=True, populate_from='title', allow_unicode=True) def __str__(self): return self.title def get_absolute_url(self): return reverse('board:detail', kwargs={ 'category': str(self.category.slug), 'slug': str(self.slug) }) def get_previous_post(self): try: previous_post = Board.objects.filter( created__gt=self.created).filter( category__title=self.category.title).last() except IndexError: return None return previous_post def get_next_post(self): try: next_post = Board.objects.filter(created__lt=self.created).filter( category__title=self.category.title).first() except IndexError: return None return next_post def save(self, *args, **kwargs): super(Board, self).save(*args, **kwargs) self.slug = '%s--%s' % (self.id, slugify(self.title, allow_unicode=True)) super(Board, self).save(*args, **kwargs) @property def like_count(self): return self.like_user_set.count()