0

I am asking if it's possible to create an attribute DictField with DictField in django restframework. If yes! Is it possible to populate it as a normal dictionary in python. I want to use it as a foreign key to store data.

Mochib
  • 1
  • 4

2 Answers2

0

There isn't such thing when you use django ORM with relational databases such as mysql or postgresql. because these kinds of relational databases have schema and certain columns for every instance to save. you should use ODM and schema-less databases such as mongodb. you can learn to work with mongodb at university.mongodb.com and you can learn about mongodb and django reading mongoengine document.

0

you can use SerializerMethodField

example:

class CustomSerializer(serializers.ModelSerializer):
    yourfield = serializers.SerializerMethodField()

    class Meta:
        model = YourModel
        fields = ('yourfield')

    def get_yourfield(self. obj)
        data = {} # or construct your custom dict here
        retrun data

for more read the doc