Skip to content
Advertisement

how to create row in model based on data fetched from JSON request from third-party crawling with “best practice”

describe the problem:

I want to crawl data from dataforseo , and save them directly in model database through model.create() method with having multi model with multi relation with models so for instance in model A have

  1. ManyToMany relation with model B

  2. ManyToMany relation with model C

  3. ManyToMany relation with model D

    and model B have relation with model C

so my question is how to save JSON response to all model mentioned above smoothly through model A create Method

response came from request:

JavaScript

Code:

view.py file

JavaScript

models.py

JavaScript

any help appreciate it

Advertisement

Answer

you can do override create method by do the following in your models.py file :

try this out:

in product model you can override create model like so

JavaScript

and in your views.py in function crawl you can just iterate through your JSON response and just add them to your model like below:

JavaScript
Advertisement