How to upload and save excel data in database django

325 views
Skip to first unread message

arvind yadav

unread,
Mar 29, 2018, 6:03:03 AM3/29/18
to Django users
this is may data format 

from django.db import models
class RegisterMember(models.Model):
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
    ) 
    id = models.AutoField(db_column='ID', primary_key=True) 
    name = models.CharField(db_column='NAME', max_length=255) 
    email = models.CharField(db_column='EMAIL', max_length=255) 
    phone = models.CharField(db_column='PHONE', max_length=5000, blank=True, null=True)
    address = models.CharField(db_column='ADDRESS',max_length=255) 
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)

Julio Biason

unread,
Mar 29, 2018, 7:49:52 AM3/29/18
to django...@googlegroups.com
Hi,

I'd export the data to CSV (which is easier to parse), create a Django Command (https://docs.djangoproject.com/en/2.0/howto/custom-management-commands/#module-django.core.management) that will open the CSV and then add the records.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ff305a58-0bf3-4f3e-9edf-adf7db879b80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

Lei Zhao

unread,
Mar 29, 2018, 8:21:17 AM3/29/18
to Django users
I think you use the library xlrd to extract data from the Excel file.
The documentation for the library can be found here at
http://xlrd.readthedocs.io/en/latest/ .

arvind yadav

unread,
Mar 29, 2018, 8:54:22 AM3/29/18
to Django users
how to use in django please explain 

Jani Tiainen

unread,
Mar 29, 2018, 10:15:39 AM3/29/18
to django...@googlegroups.com
Hi, there are few ways to do that, both represented in previous posts.

Simpler one is to export data as CSV since it's simpler to read in Python (Python has built-in CSV reader/writer)

Complex one is to use some library to read Excel files directly. See https://www.datacamp.com/community/tutorials/python-excel-tutorial  for more information.

With anycase, use Django (model) form to put data there - it makes sure that data is valid and is converted format that is suitable for Django. It also eliminates checks of malicious people doing malicious stuff to your system.

And finaly, save the data. Repeat for all data chunks and you're done. It's really that simple.


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...
Reply all
Reply to author
Forward
0 new messages