1

Suppose I am getting a list of user from an api in json format and I want to save it in my User model in django. Saving the user might not be a problem but I want that data continuously.

I am getting an api from a system which sends me the list of user who sent emails. These users go on increasing.

Now I am getting a list of users. I want to save these users in my database. But the questioning part is, suppose 10 user has sent messages I am getting list of 10 users from api then I will save it say like

usr = User()
usr.username = data["username"]
usr.save()

Now what when 1 more user sends the email. Now I will be receiving 11 user.

Here I want continuously add the updated user in my database. How to do this ?

I dont know if I have made it clear or not but need help on this

gamer
  • 5,673
  • 13
  • 58
  • 91
  • I am not sure if I understood the question but you can make the `username` field unique to prevent it from recorded into the table multiple times. – Selcuk Feb 25 '15 at 17:53
  • I dont want to make it unique I want username of same character can be saved. Consider username as name... But the thing is how can I save continuously – gamer Feb 25 '15 at 17:55
  • It's not clear what "continuously" means in this context. Do you mean that you need to save multiple users in a single request? Can you show an example of the JSON input you want to act on? – dylrei Feb 25 '15 at 18:15
  • Lets say its not username its phone number. I want my database updated continuously when someone email. – gamer Feb 26 '15 at 02:18

2 Answers2

0

I guess your problem is how to trigger the retrieving of the emails.

A very easy way to do this is to use a timed autoreload - you can do this easily in html. See this answer. Then your django view can check for new emails and respond with the new data.

Community
  • 1
  • 1
ger.s.brett
  • 3,267
  • 2
  • 24
  • 30
0

as per my understanding, you want to check for the new data entries periodically and save the new records into db. Right?

So for periodic tasks Celery is the best utility. once you get data periodically then get db data into list_db and API data into API_list. Now start comparing both the lists data and store the new one into db.

I hope this will help.

Sajjad Ali
  • 116
  • 10