Ejemplo n.º 1
0
class Post(models.Model):
    title = models.CharField(max_length=200)
    text = SummernoteTextField()
    created_date = models.DateTimeField(default=timezone.now)

    def __str__(self):
        return self.title
Ejemplo n.º 2
0
class Solution(models.Model):
    class Meta:
        verbose_name = "Решение"
        verbose_name_plural = "Решения"

    username = models.ForeignKey(User,
                                 on_delete=models.CASCADE,
                                 verbose_name='Автор')
    task = models.ForeignKey(Task,
                             on_delete=models.CASCADE,
                             default=DEFAULT_TASK_ID,
                             verbose_name='Задача')
    answer = models.CharField(max_length=2000, verbose_name='Ответ')
    description = SummernoteTextField(verbose_name='Решение')
    verdict = EnumField(Virdict,
                        max_length=500,
                        default=Virdict.WRONG_ANSWER,
                        verbose_name='Вердикт')
    submitTime = models.DateTimeField(default=datetime.timezone.now(),
                                      blank=True,
                                      verbose_name='Время')
    need_rang = models.IntegerField(verbose_name='Ранг проверки')
    comments = models.ManyToManyField(Message,
                                      blank=True,
                                      verbose_name='Комментарии жури')
    themesol = models.ForeignKey("Theme",
                                 on_delete=models.CASCADE,
                                 verbose_name="Решение по теме")
Ejemplo n.º 3
0
class Note(TimeStampedModel):
    ''' subclass of time stamped model, includes a created and modified field 
        authstamped created_by is subbed out
    '''
    # fields
    # uses randomchar from extensions to generate unique chars
    id = RandomCharField(length=12, unique=True, primary_key=True)
    title = models.CharField(max_length=50, blank=True, default=title_default)
    content = SummernoteTextField(blank=True)
    notebook = models.ManyToManyField('notebooks.NoteBook',
                                      related_name='notebook_notes',
                                      blank=True)
    created_by = models.ForeignKey(UserModel,
                                   on_delete=models.CASCADE,
                                   null=False,
                                   blank=True,
                                   related_name='created_notes')

    # custom Manager
    objects = NoteManager()

    def __str__(self):
        return f'note title: {self.title}'

    @property
    def get_absolute_url(self):
        """Returns the url to access a particular instance of the model."""
        return reverse('note_detail', args=[str(self.id)])
Ejemplo n.º 4
0
class Comment(ModeratedObjectMixin, MPTTModel):
    user = models.ForeignKey(to=get_user_model(), on_delete=models.PROTECT, editable=False)
    content_type = models.ForeignKey(to=ContentType, on_delete=models.PROTECT, editable=False)
    object_id = models.PositiveIntegerField(editable=False)
    content_object = GenericForeignKey('content_type', 'object_id')
    text = SummernoteTextField(_('Text'), validators=[SummernoteMinValueValidator(10)])
    parent = TreeForeignKey('self',
                            on_delete=models.CASCADE,
                            null=True,
                            blank=True,
                            related_name='children',
                            editable=False)

    objects = ModeratedTreeManager()

    class MPTTMeta:
        order_insertion_by = ['object_id', 'date_created']

    def get_absolute_url(self):
        return self.content_object.get_absolute_url() + '?comment=' + str(self.pk)

    def get_admin_url(self):
        url = admin_urlname(self._meta, 'change')
        return reverse(url, args=(self.pk,))

    def __str__(self):
        return '@%s, %s' % (self.user, truncatechars(self.text_representation(), 125))

    @display(description='text')
    def text_representation(self):
        return strip_tags(mark_safe(self.text))
Ejemplo n.º 5
0
class Services(models.Model):
    name = models.CharField(max_length=50)
    slug = models.SlugField(editable=False, max_length=130)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    intro = models.CharField(max_length=100, unique=True)
    pricing = models.IntegerField()
    detail = SummernoteTextField()
    image = models.ImageField(default='default.png', upload_to='services')
    # author = models.ForeignKey(Profile, on_delete=models.CASCADE) # use self.request.user.id == to get id of current logged in user
    author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = 'Services on Offer'
        ordering = ('name', )

    def save(self, *args, **kwargs):
        value = self.intro
        self.slug = slugify(value)
        super().save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('service-detail', kwargs={'slug': self.slug})
Ejemplo n.º 6
0
class PostForm(ModelForm):
    content = SummernoteTextFormField()
    description = SummernoteTextField()

    class Meta:
        model = Post
        fields = ('title', 'category', 'post_image', 'description', 'content')
Ejemplo n.º 7
0
class Question(models.Model):
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    question = SummernoteTextField()
    timestamp = models.DateTimeField(auto_now_add=True, blank=True)

    def __str__(self):
        return self.author
Ejemplo n.º 8
0
class UserProfile(models.Model):
    """A user profile model that extends the built-in user model"""
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    avatar = models.ImageField(default='images/default.jpeg',
                               upload_to='images')
    dob = models.DateField(null=True, blank=True)
    bio = SummernoteTextField(blank=True)
    location = models.CharField(max_length=255, blank=True)
    hobby = models.CharField(max_length=255, blank=True)
Ejemplo n.º 9
0
class Question(models.Model):
    class Meta:
        verbose_name = 'Вопрос'

    station = models.CharField(max_length=200, verbose_name="Название станции")
    text = SummernoteTextField(verbose_name="Текст вопроса")
    who = models.ForeignKey(User,
                            on_delete=models.CASCADE,
                            verbose_name="Для кого вопросы")
Ejemplo n.º 10
0
class Information(models.Model):
    class Meta:
        verbose_name = 'Информация'

    station = models.CharField(max_length=200, verbose_name="Название станции")
    text = SummernoteTextField(verbose_name="Информация")
    who = models.ForeignKey(User,
                            on_delete=models.CASCADE,
                            verbose_name="Для кого вопросы")
Ejemplo n.º 11
0
class Article(models.Model):
    author = models.ForeignKey('auth.user', on_delete=models.CASCADE)
    title = models.CharField(max_length=100)
    body = SummernoteTextField()
    date = models.DateField()
    time = models.TimeField()

    def __str__(self):
        return self.title
Ejemplo n.º 12
0
class Answer(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    content = SummernoteTextField()
    question = models.ForeignKey(Question,
                                 on_delete=models.CASCADE,
                                 related_name='answers')
    created_on = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "Answer to {}.".format(self.question)
Ejemplo n.º 13
0
class Post(ModeratedObjectMixin, models.Model):

    slug = models.SlugField(null=False, blank=False)
    user = models.ForeignKey(to=get_user_model(),
                             on_delete=models.PROTECT,
                             editable=False)
    category = models.IntegerField(_('Category'),
                                   choices=CategoryTypes.choices())
    title = models.CharField(_('Title'), max_length=200)
    feed_cover = models.ImageField(_('Feed cover'),
                                   upload_to='blog/feed_covers')
    feed_article_preview = SummernoteTextField(_('Feed article preview'),
                                               blank=True)
    text = SummernoteTextField(_('Text'),
                               validators=[SummernoteMinValueValidator(500)])
    tags = TaggableManager()

    class Meta:
        ordering = ('-date_created', )

    def __str__(self):
        return self.title

    @property
    def url_kwargs(self):
        return {'pk': self.pk, 'slug': self.slug}

    def get_absolute_url(self):
        return reverse('post_detail', kwargs=self.url_kwargs)

    def get_edit_url(self):
        return reverse('post_edit', kwargs=self.url_kwargs)

    def get_admin_url(self):
        url = admin_urlname(self._meta, 'change')
        return reverse(url, args=(self.pk, ))

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.title)
        return super().save(*args, **kwargs)
Ejemplo n.º 14
0
class Location(models.Model):
    name = models.CharField(max_length=200)
    address = models.CharField(max_length=300)
    email = models.EmailField(max_length=100, blank=True)
    phone = models.CharField(max_length=30, blank=True)
    website = models.CharField(max_length=100, blank=True)
    coordinates = models.CharField(max_length=100, blank=True)
    description = SummernoteTextField(blank=True)
    owner = models.CharField(max_length=100, blank=True)

    def __str__(self):
        return self.name
Ejemplo n.º 15
0
class Post(models.Model):
    title = models.CharField(max_length=200)
    body = SummernoteTextField()
    image = models.ImageField(default='default.jpg', upload_to='blog_pics')
    date_published = models.DateTimeField(auto_now_add=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('blog:home')
Ejemplo n.º 16
0
class Category(TimeStampedModel, Active):
    restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE)
    name = models.CharField("Categoria", max_length=50)
    description = SummernoteTextField(blank=True)

    def __str__(self):
        return str(self.name)

    class Meta:
        ordering = ("name", )
        verbose_name = "categoria"
        verbose_name_plural = "categorias"
Ejemplo n.º 17
0
class Article(models.Model):
    STATUS_CHOICES = (
        ('d', '草稿'),
        ('p', '发表'),
    )
    article_id = models.CharField(verbose_name='标号', max_length=100)
    title = models.CharField(verbose_name='标题', max_length=100)
    # content = models.TextField(verbose_name='正文', blank=True, null=True)
    content = SummernoteTextField(verbose_name='正文', null=True)
    status = models.CharField(verbose_name='状态',
                              max_length=1,
                              choices=STATUS_CHOICES,
                              default='p')
    views = models.PositiveIntegerField(verbose_name='浏览量', default=0)
    created_time = models.DateTimeField(verbose_name='创建时间', default=now)
    category = models.ForeignKey(Category,
                                 verbose_name='分类',
                                 on_delete=models.CASCADE,
                                 blank=False,
                                 null=False)
    tags = models.ManyToManyField(Tag, verbose_name='标签集合', blank=True)

    # 使对象在后台显示更友好
    def __str__(self):
        return self.title

    # 更新浏览量
    def viewed(self):
        self.views += 1
        self.save(update_fields=['views'])

    # 下一篇
    def next_article(self):  # id比当前id大,状态为已发布,发布时间不为空
        return Article.objects.filter(id__gt=self.id,
                                      status='p',
                                      pub_time__isnull=False).first()

    # 前一篇
    def prev_article(self):  # id比当前id小,状态为已发布,发布时间不为空
        return Article.objects.filter(id__lt=self.id,
                                      status='p',
                                      pub_time__isnull=False).first()

    class Meta:
        ordering = ['-created_time']  # 按文章创建日期降序
        verbose_name = '文章'  # 指定后台显示模型名称
        verbose_name_plural = '文章列表'  # 指定后台显示模型复数名称
        db_table = 'article'  # 数据库表名
        get_latest_by = 'created_time'
Ejemplo n.º 18
0
    def test_field(self):
        from django import forms
        from django_summernote.fields import SummernoteTextField

        class SimpleModel1(models.Model):
            foobar = SummernoteTextField()

        class SimpleForm(forms.ModelForm):
            class Meta:
                model = SimpleModel1
                fields = "__all__"

        f = SimpleForm()
        html = f.as_p()
        url = reverse('django_summernote-editor', kwargs={'id': 'id_foobar'})

        assert url in html
        assert 'id="id_foobar"' in html

        illegal_tags = '<script></script>'
        model_field = SummernoteTextField()
        model_instance = SimpleModel1()
        cleaned_text = model_field.clean(illegal_tags, model_instance)
        self.assertEqual(cleaned_text, '&lt;script&gt;&lt;/script&gt;')
Ejemplo n.º 19
0
class Entry(models.Model):
    """Something specific learned about a topic"""
    topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
    text = SummernoteTextField()
    date_added = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name_plural = 'entries'

    def __str__(self):
        """Return a string representation of the model."""
        if len(self.text) > 50:
            return self.text[:50] + "..."
        else:
            return self.text
Ejemplo n.º 20
0
class CommentForm(forms.ModelForm):
    class Meta:
        model = models.Comment
        fields = [
            "text",
        ]
        widgets = {
            "text": SummernoteWidget(),
        }

    text = SummernoteTextField()

    def save(self, *args, **kwargs):
        comment = super().save(commit=False)
        return comment
Ejemplo n.º 21
0
class Announcement(models.Model):
    title = models.CharField(verbose_name='标题', max_length=32)
    content = SummernoteTextField(verbose_name='内容', null=True)
    # create_timestamp = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    last_edit_timestamp = models.DateTimeField(verbose_name='最后编辑时间',
                                               auto_now=True)
    public_time = models.DateTimeField(verbose_name='公布时间',
                                       default=timezone.now)

    class Meta:
        verbose_name = '公告'
        verbose_name_plural = '公告'
        indexes = [models.Index(fields=['-public_time'])]

    def __str__(self):
        return self.title
Ejemplo n.º 22
0
class Articles(models.Model):
    article_title = models.CharField(max_length=250)
    article_desc = models.CharField(max_length=300)
    article_keywords = models.CharField(max_length=1000)
    article_slug = models.SlugField(max_length=200)
    article_auther = models.ForeignKey(Auther, on_delete=models.CASCADE)
    article_img = models.ImageField(upload_to='article_imgs')
    article_date = models.DateField(default=datetime.date.today)
    article_content = SummernoteTextField()
    article_tags = TaggableManager(blank=True)
    is_updated = models.BooleanField(default=False)
    is_deleted = models.BooleanField(default=False)
    created_at = models.DateField(default=datetime.date.today)
    updated_at = models.DateField(auto_now=False, null=True)
    deleted_at = models.DateField(auto_now=False, null=True)

    def __str__(self):
        return self.article_slug
Ejemplo n.º 23
0
class Partner(models.Model):
	name = models.CharField(max_length=200)
	email = models.EmailField(max_length=100)
	phone = models.CharField(max_length=30)
	website = models.CharField(max_length=100)
	address = models.CharField(max_length=400)
	image = models.ForeignKey(
		Image, related_name="partners", on_delete=models.SET_NULL, 
		null=True, blank=True)
	description = SummernoteTextField()
	active = models.BooleanField(default=True)
	created_on = models.DateTimeField(auto_now_add=True)
	
	class Meta:
		ordering = ['-created_on']

	def __str__(self):
		return self.name
Ejemplo n.º 24
0
class ProjectInfo(models.Model):
    project_direction = models.CharField(max_length = 200, default = '')
    project_creators = models.CharField(max_length = 200, default = '')
    project_state = models.CharField(max_length = 1, default = '0')
    project_name = models.CharField(max_length = 200)
    project_root = models.CharField(max_length = 200)
    project_short = models.CharField(max_length = 200, default = '')
    project_text = SummernoteTextField(verbose_name="project text")
    project_popularity = models.IntegerField(default = 0)
    project_iseng = models.CharField(max_length = 1, default = '1')
    #project_text_task = SummernoteTextField(verbose_name="project text task")
    #project_text_methods = SummernoteTextField(verbose_name="project text methods")
    #project_text_results = SummernoteTextField(verbose_name="project text results")
    #project_text_discussions = SummernoteTextField(verbose_name="project text discussions")
    #project_text_conclusions = SummernoteTextField(verbose_name="project text conclusions")
    project_picture = models.ImageField(upload_to='projects_pics',blank=True)
    project_acount = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    def __str__(self):
        return self.project_name
Ejemplo n.º 25
0
class Post(models.Model):
    judul = models.CharField(max_length=200, unique=True)
    id = models.AutoField(primary_key=True, editable=False, default=None)
    author = UserForeignKey(auto_user_add=True)
    TIPE = (('Pemberitahuan/Pengumuman', 'Pemberitahuan/Pengumuman'),
            ('Cerita Pendek/Novel',
             'Cerita Pendek/Novel'), ('Edit/Video Musik', 'Edit/Video Musk'),
            ('Desain Grafis', 'Desain Grafis'), ('Art/Gambar', 'Art/Gambar'))
    tipe = models.TextField(choices=TIPE, max_length=100)
    konten = SummernoteTextField(default=None)
    Diperbarui_Pada = models.DateTimeField(auto_now=True)
    Dibuat_Pada = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(choices=STATUS, default=0)

    class Meta:
        ordering = ['-Dibuat_Pada']

    def __str__(self):
        return self.judul
Ejemplo n.º 26
0
class Booking(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    email = models.EmailField(max_length=100)
    description = SummernoteTextField()
    reference = models.IntegerField()

    amount = models.IntegerField(default=0)
    seats = models.IntegerField(default=1)
    discount = models.IntegerField(default=0)

    payment_status = models.IntegerField(choices=PAY_STATUS, default=0)
    clearance = models.IntegerField(choices=CLEARANCE, default=0)

    ticket = models.CharField(max_length=15, blank=True)

    created_on = models.DateTimeField(auto_now_add=True)
    updated_on = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.email
Ejemplo n.º 27
0
class Article(models.Model):
    title = models.CharField(verbose_name='标题', max_length=100)
    # content = models.TextField(verbose_name='正文', blank=True, null=True)
    content = SummernoteTextField(null=True)
    created_time = models.DateTimeField(verbose_name='创建时间', default=now)
    author = models.ForeignKey(Author,
                               verbose_name='作者列表',
                               on_delete=models.CASCADE,
                               blank=False,
                               default=1)

    # 使对象在后台显示更友好
    def __str__(self):
        return "{}".format(self.title)

    class Meta:
        ordering = ['-created_time']  # 按文章创建日期降序
        verbose_name = '文章'  # 指定后台显示模型名称
        verbose_name_plural = '文章列表'  # 指定后台显示模型复数名称
        db_table = 'article'  # 数据库表名
        get_latest_by = 'created_time'
Ejemplo n.º 28
0
class WritePostForm(forms.ModelForm):
    class Meta:
        model = models.Post
        fields = [
            "title",
            "contents",
            "board",
        ]
        widgets = {
            "contents": SummernoteWidget(),
        }

    title = forms.CharField(
        label="title",
        widget=forms.TextInput(attrs={"placeholder": "title of post"}),
        required=True,
    )

    contents = SummernoteTextField()

    BOARD_FREE = "free"
    BOARD_NOTICE = "notice"

    BOARD_CHOICES = ((BOARD_FREE, "Free Board"), (BOARD_NOTICE,
                                                  "Notice Board"))

    board = forms.ChoiceField(label="Choice a board",
                              widget=forms.Select(),
                              choices=BOARD_CHOICES)

    field_order = [
        "title",
        "board",
        "contents",
    ]

    def save(self, *args, **kwargs):
        post = super().save(commit=False)
        return post
Ejemplo n.º 29
0
class Article(models.Model):
    author = models.CharField(max_length=90)
    title = models.CharField(max_length=255)
    snippet = models.CharField(max_length=100,blank=True)
    thumbnail = models.ImageField(upload_to='article/thumbnail',blank=True)
    slug = models.SlugField(allow_unicode=True,unique=True)
    text = SummernoteTextField()
    created_at = models.DateTimeField(auto_now=True)
    published_date = models.DateTimeField(blank=True,null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.title

    def save(self,*args,**kwargs):
        self.slug = slugify(self.title)
        super().save(*args,**kwargs)

    def get_absolute_url(self):
        return reverse('blog:detail',kwargs={'slug':self.slug})
Ejemplo n.º 30
0
class Post(models.Model):
    title = models.CharField(max_length=100)
    image = models.ImageField(default='default.jpg', upload_to='posts_images')
    content = SummernoteTextField()
    date_posted = models.DateTimeField(default=timezone.now)
    active = models.BooleanField(default=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    tags = TaggableManager()

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('post-detail', kwargs={'pk': self.pk})

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)

        img = Image.open(self.image.path)

        if img.height > 600 or img.width > 600:
            output_size = (600, 600)
            img.thumbnail(output_size)
            img.save(self.image.path)