How to push data fetched from excel to DB using Django?

116 views
Skip to first unread message

ratnadeep ray

unread,
May 8, 2020, 8:03:40 AM5/8/20
to Django users
Hi all, 

Can anyone let me know how to push the fetched data from an excel to any DB using Django? 

Kasper Laudrup

unread,
May 8, 2020, 8:57:43 AM5/8/20
to django...@googlegroups.com
Hi Ratnadeep,
It's not very clear what you mean by "the fetched data". Have you
fetched some data already? In which format?

If you need to extract data from an excel sheet, this was the first
guide I could find:

https://www.geeksforgeeks.org/reading-excel-file-using-python/

Also, "any DB" is extremely vague. Do you have a database already? Or do
you just want to go for whatever database is the best suited for
whatever you are trying to achieve?

And what exactly do you want to use Django for? Django is a web
framework and nothing in your question mentions anything about that...

Kind regards,

Kasper Laudrup



> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1e970207-0c86-4925-b4c8-dbce7c7c069d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/1e970207-0c86-4925-b4c8-dbce7c7c069d%40googlegroups.com?utm_medium=email&utm_source=footer>.

Derek

unread,
May 8, 2020, 9:50:31 AM5/8/20
to Django users
If you can, use an existing app:



On Friday, 8 May 2020 14:57:43 UTC+2, Kasper Laudrup wrote:
Hi Ratnadeep,

On 08/05/2020 14.03, ratnadeep ray wrote:
> Hi all,
>
> Can anyone let me know how to push the fetched data from an excel to any
> DB using Django?
>

It's not very clear what you mean by "the fetched data". Have you
fetched some data already? In which format?

If you need to extract data from an excel sheet, this was the first
guide I could find:

https://www.geeksforgeeks.org/reading-excel-file-using-python/

Also, "any DB" is extremely vague. Do you have a database already? Or do
you just want to go for whatever database is the best suited for
whatever you are trying to achieve?

And what exactly do you want to use Django for? Django is a web
framework and nothing in your question mentions anything about that...

Kind regards,

Kasper Laudrup



> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send

ratnadeep ray

unread,
May 9, 2020, 1:07:33 AM5/9/20
to Django users
Hi Kasper, 

I want to read the data from excel and the retrieved data should be pushed to a DB, in my case it's MySQL. 

I believe the steps mentioned in the link https://www.geeksforgeeks.org/reading-excel-file-using-python/ , should be written in the views.py file. Am I right? 

Please clarify these because I am pretty new to Django. 

Thanks. 

ratnadeep ray

unread,
May 9, 2020, 1:09:34 AM5/9/20
to Django users
Thanks Derek for this. 

Motaz Hejaze

unread,
May 9, 2020, 1:28:02 AM5/9/20
to Django users
first , check your excel file , see what are the columns types ..
then , make a model in django models.py and choose model fields to be the same type as each column in the excel file ..
in your views.py make a function that will read the excel file from the file location on your machine ..
in this function use the code provided in Kasper tutorial link  https://www.geeksforgeeks.org/reading-excel-file-using-python/
while you are looping through each row in your excel file you can populate the model you created in models.py ..
but if the excel file is too large , this will block your code , maybe cause the database to be locked too ..
if you face this problem consider using threading or asyncio ..

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4cca72a6-1b5d-4fa8-8c60-c3593cdaca90%40googlegroups.com.

DAVID ALEJANDRO Pineda

unread,
May 11, 2020, 10:26:14 PM5/11/20
to django...@googlegroups.com
You can use the Fixtures feature

First, pass to csv your spreadsheet

Then, you have in mind the model or set of models....

ModelA
ModelB

The fields, the data type for every field.

Then, convert to a file of JSON to load with the fixture command.

I can share with you my code that do that:
https://gitlab.com/pineiden/csv-2-json


Other path is loading the django settings and reading every row and convert to a dict and init the object
Like this.

Any question, write to me ;)






El vie., 8 may. 2020 a las 8:04, ratnadeep ray (<ratna...@gmail.com>) escribió:
Hi all, 

Can anyone let me know how to push the fetched data from an excel to any DB using Django? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.


--
Ingeniero Civil Electricista U. de Chile
F: +56 9 82142267 - dpi...@ug.uchile.cl
Reply all
Reply to author
Forward
0 new messages