Home > Software design >  Define field in Django which can be of any type
Define field in Django which can be of any type

Time:11-10

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.

CodePudding user response:

You can use Charfield in your model when it should be more generic. Take into consider that your model has to map the database.

  • Related