Home > Software design >  What is the simplest way to store a list of numbers in Django model without using third party databa
What is the simplest way to store a list of numbers in Django model without using third party databa

Time:10-21

I want to store a list of numbers in Django model without using third party databases like MySQL, PostgreSQL etc. I want a simple approach. I don't think that there is any built-in field like PositiveSmallIntegerField, CharField etc but please do correct me if I am wrong. Is there a way I can use the built-in fields in order to achieve the result or is there a different approach? Please note that I need to add / remove / extract those numbers also.

Can someone help me with it?

CodePudding user response:

Even easier, I believe it exists already...

from django.db.models.fields import CommaSeperatedIntegerField

and then you will notice that the system will advise you to use the following:

CharField(validators=[validate_comma_separated_integer_list])

and you can import validate_comma_separated_integer_list from

from django.core.validators import validate_comma_separated_integer_list
  • Related