Define field in Django which can be of any type
Question:
Pymodm is being used to define my model for the MongoDB collection in Django. I want to declare a field that can store values of any type (List, String, or Integer).
from pymodm import MongoModel, fields
class DefinitionEntity(MongoModel):
version = fields.IntegerField(required=True)
value = fields.CharField(required=True)
I want the "value" field to accept multiple types. Please tell me how to define that.
Answers:
You can use Charfield in your model when it should be more generic. Take into consider that your model has to map the database.
Pymodm is being used to define my model for the MongoDB collection in Django. I want to declare a field that can store values of any type (List, String, or Integer).
from pymodm import MongoModel, fields
class DefinitionEntity(MongoModel):
version = fields.IntegerField(required=True)
value = fields.CharField(required=True)
I want the "value" field to accept multiple types. Please tell me how to define that.
You can use Charfield in your model when it should be more generic. Take into consider that your model has to map the database.