django-quill-editor icon indicating copy to clipboard operation
django-quill-editor copied to clipboard

How to manually create objects in the code

Open a35205905 opened this issue 4 years ago • 3 comments

Sorry, my English is not very good, But I really like this package and actually used it in the project.

I defined a model.

class News(SoftDeletableModel):
    title = models.CharField(max_length=255, null=False)
    content = QuillField(null=True)
    news_category = models.ForeignKey(NewsCategory, on_delete=models.PROTECT, null=False)
    status = models.BooleanField(null=False, default=False)
    order = models.PositiveSmallIntegerField(null=False, default=0)
    display_date = models.DateField(null=False, default=timezone.now)
    create_datetime = models.DateTimeField(auto_now_add=True)
    modify_datetime = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = 'news'
        verbose_name_plural = 'news'
        db_table = 'news'

    def __str__(self):
        return self.title

I want to create it manually in the code, like this.

News.objects.create(title='title', content='content', display_date=timezone.now().date())

The result of the operation shows an error, How can I set the correct value in content?

Thank you.

a35205905 avatar Sep 03 '20 02:09 a35205905

I was also looking for a way to do this. I need to migrate data that is already formatted into the quill format from an excel file. Did you find a way to manually create the objects and save in quill json format?

cdesch avatar Sep 11 '20 15:09 cdesch

django_quill.quill.Quill is the underlying method. the constructor takes a json_string argument, so this:

django_quill.quill.Quill('{"delta":"{\\"ops\\":[{\\"insert\\":\\"this is a test!\\"},{\\"insert\\":\\"\\\\n\\"}]}","html":"<p>this is a test!</p>"}')

will give you what you're looking for

ghost avatar Nov 02 '20 07:11 ghost

I guess, the issue is resolved.

gokselcoban avatar Feb 10 '21 17:02 gokselcoban