2

I'm trying to explore Django and djgono for fun. I want to create a document in the db which is similar to the following document:

{
    "title": "Djongo - trying to create a list field",
    "body": "I cannot do basic programming...epic fail!",
    "tags": ["django","djongo","list"]
}

Following is my code:

from djongo import models

class Post(models.Model):
    title = models.CharField(max_length=255)
    body = models.TextField(max_length=1000)
    tags = models.JSONField()

I tried to add the document from django admin. Entered exactly ["django","djongo","list"] in the Tags field. I get the following error:

Value: ["django","djongo","list"] stored in DB must be of type dict/listDid you miss any Migrations?

Clearly I am going horribly wrong somewhere. Would be happy if someone pointed me in the right direction.

Thanks!

EDIT: further clarification added.

nabil.adnan1610
  • 424
  • 3
  • 10
  • Do you get any errors? – Brian Destura Aug 10 '21 at 23:49
  • I think i need to clarify a bit more. I tried to add the document from django admin. entered exactly ["django","djongo","list"] in the Tags field. I get the following error: Value: ["django","djongo","list"] stored in DB must be of type dict/listDid you miss any Migrations? – nabil.adnan1610 Aug 11 '21 at 00:09
  • Right because when you input from the admin, it's a string. You need to somehow change that into a list – Brian Destura Aug 11 '21 at 00:12
  • Lol I got that. I'm just trying to figure out how to enter a list in that field. Seems like no matter what I type Django admin is saving it as a text. Do I have to find ways other than Django admin to add similar data? – nabil.adnan1610 Aug 12 '21 at 00:55

0 Answers0