Search code examples
pythondjangodjango-modelsmodels

How to register a django model field with any type?


I have built an API With Django REST Framework. On client side I use Angular and I have an class that looks like:

export class Property{
  id: number;
  value: any;                                                          
}

The value property can take many variables with many types: string, array or number... How can I save value with my API?

from django.db import models                                      
class Property(models.Model):
    value = ?

I've looked a bit. I found Django Generic's relations. But I have no idea how to use it.

Can you help me?


Solution

  • Python doesn't have an 'any' type like typescript! However.. I sometimes use Charfield on models when a value may be generic.. It is not so much generic but consider that your model must map a database.. And databases don't have generic types of values