I have a task to create a simple post API to send a visitor messages through a contact form that contain fields like full_name,address,phone etc. But instead of creating a model, I have to use an already existing model which has a Jsonfield. Now what I need to do is to use that jsonfield which will have all the fields like name, address etc.
class Core(models.Model):
"""
Model that saves the corresponding credentials for the slug.
"""
slug = models.CharField(max_length=255, null=False)
example = models.JSONField(null=False, default=dict)
def __str__(self) -> str:
return self.slug
If it was done in a regular way by creating a model, it would have been like this.
class Contacts(models.Model):
full_name = models.CharField(max_length=100,blank=True,default="")
email = models.EmailField()
phone = models.CharField(max_length= 16)
address = models.CharField(max_length=255,blank=True,default="")
message = RichTextField()
def __str__(self):
return self.email
Now, how should I send these fields data in a dictionary without in that JsonField without creating a Contacts model?