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.
Asked
Active
Viewed 553 times
0
-
can u please show us what you have tried? – Sekar Raj May 25 '17 at 12:12
-
You can use django jsonfield in models – priya May 25 '17 at 12:32
-
Refer the url : https://stackoverflow.com/questions/37629501/django-rest-framework-listfield-and-dictfield Hope it helps – priya May 25 '17 at 12:37
2 Answers
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.

yekmolsoheil
- 54
- 4
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

Muhammad Sholeh
- 11
- 4