response = requests.post(
"http://localhost:8557/api/v1/test", json=data)
print("Получен ответ:")
json_var = response.content.decode("utf-8")
print(json.loads(json_var))
print(json.loads(response.content)) - помог избавиться только от такой записи:
b'"{\\n \\"text\\": \\"\\\\u0441\\\\u0430\\\\u043b\\\\u044e\\\\u0442
import json
json_var = b'{\n \"text\": \"\\u0441\\u0430\\u043b\\u044e\\u0442"}'.decode("UTF-8")
print(json.loads(json_var))
{'text': 'салют'}
class Article(models.Model):
title = models.CharField(verbose_name='Заголовок', max_length=100)
cover = models.ImageField(verbose_name='Обложка', upload_to=get_file_path)
category = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='Категория')
autor = models.ForeignKey(UserAccount, on_delete=models.CASCADE, verbose_name='Автор', null=True, blank=True)
article_body = models.TextField(verbose_name='Тело статьи')
def __str__(self):
return self.title
class Comment(models.Model):
autor = models.ForeignKey(UserAccount, on_delete=models.CASCADE, verbose_name='Автор')
article = models.ForeignKey(Article, on_delete=models.CASCADE, verbose_name='Статья')
datetime_post = models.DateTimeField(auto_now=True, verbose_name='Дата:')
text_body = models.TextField(verbose_name='Комментарий', max_length=500)
# Отправляем сигнал
@receiver(post_save, sender=Article)
def update_stock(sender, instance, **kwargs):
user = instance.autor
Comment.objects.create(autor=user,article=instance, text_body='Предлагаю ознакомиться')