django-quill-editor
django-quill-editor copied to clipboard
How to manually create objects in the code
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.
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?
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
I guess, the issue is resolved.