I have a model as below:
class Person(models.Model): name = model.CharField(max_length = 255) mobile = model.IntegerField(null = True) city = model.CharField(max_length = 255) Now i need to create a model object using a json as below:
data = { "name" : "John", "age" : 31, "city" : "New York", "mobile" : 1234432156, "address" : "xyz" } In the above json, name, mobile, city are the fields in Person model. I have to create a model object using the above json. I have done like this:
Person.objects.create(**data) But it is throwing an error saying 'age' is invalid keyword argument for this function. My understanding is that, it is throwing error since there is no age field in the model.
How to create the model instance with such a json where all the keys are not the fields in the model.
agemight be not be used here, but it can be used in some other place.