C
C
ckatala2019-01-17 19:03:21
Django
ckatala, 2019-01-17 19:03:21

How to connect any Django-React text editor?

React
frontend Django backend
I want to connect a text editor
On the front, the editor works fine, but when saving, it passes json instead of text
What should I write in the content model in django?
now the model looks like this

class Article(models.Model):
  DRAFT = "D"
  PUBLISHED = "P"
  STATUS = (
    (DRAFT, _("Draft")),
    (PUBLISHED, _("Published")),
  )
  author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, 
       related_name="posted_articles")
  title = models.CharField(max_length=255, null=False, unique=True)
  slug = models.SlugField(max_length=80, null=True, blank=True)
  content = models.TextField(default="", null=True, blank=True)
  status = models.CharField(max_length=1, choices=STATUS, default=DRAFT)
  rank_score = models.FloatField(default=0.0)
  created_at = models.DateTimeField(default=timezone.now)
  updated_at = models.DateTimeField(auto_now=True)
  objects = ArticleQuerySet.as_manager()

  class Meta:
    verbose_name = _("Article")
    verbose_name_plural = _("Articles")
    ordering = ("-created_at",)

  def __str__(self):
    return self.title

  def save(self, *args, **kwargs):
    if not self.slug:
      self.slug = slugify(f"{self.author.username}-{self.title}", to_lower=True, max_length=80)
    self.read_time = get_read_time(markdownify(self.content))
    super().save(*args, **kwargs)

  def get_absolute_url(self):
    return reverse("article_detail", kwargs={"slug": self.slug})

  def get_markdown(self):
    return markdownify(self.content)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question