Home > Back-end >  Is there any way to store list in database in django?
Is there any way to store list in database in django?

Time:04-07

This is the list I have to insert in the database

This is the error I got while inserting in the database

This is my model

CodePudding user response:

If you use Postgres db then you have access to ArrayField: https://docs.djangoproject.com/en/4.0/ref/contrib/postgres/fields/#arrayfield

Other then that... You can for example store students ids as ManytoMany field

CodePudding user response:

Update marks to be an ArrayField.

marks = models.ArrayField(models.IntegerField(), default= [], blank=False, null=False)

then you can initialize the new object just fine. if you need to update the array after the object's creation, you can do that like so:

result.marks = [0,90]
result.save()
  • Related