Django Excel Import Data Help

164 views
Skip to first unread message

Jasmine Chua

unread,
Jul 23, 2019, 7:35:15 AM7/23/19
to Django users
Hi,

I am struggling to correctly map my Excel data tab of CaseSummary to my CaseSummary model using Django-Excel. I am getting the error that CaseSummary does not match any given models when it should match my CaseSummary model. I have no problem previously in uploading data from a single tab spreadsheet to a single model without any foreign keys or relationships to other models. However, my objective is to upload a spreadsheet containing multiple tabs of data and my models have foreign keys, one-to-one and many-to-many fields too. However, i cannot seem to find good documentation online about how to do this. i really hope to receive some tips from this mailing list as i have been banging my head against the wall on this one. I look forward to hear from you guys. Thank you very much in advance! 

More details below. 

Error message screenshot while uploading my Excel Spreadsheet:

Screenshot 2019-07-23 at 5.16.03 PM.png


Screenshot of my CaseSummary tab in my spreadsheet. Fictitious data.

Screenshot 2019-07-23 at 5.40.04 PM.png

My CaseSummary Model

Screenshot 2019-07-23 at 5.41.15 PM.png




I am running Python version 2.2.2, Django version 3.7.3 and Django-Excel 0.0.10. 
While reading the documentation at Django-Excel page (http://django.pyexcel.org/en/latest/), i am not sure if i understand choice_func function correctly. I understand the reason why choice_func is required because it has a foreign key to Question and its Question column has to be translate to a Question instance. However, i am guessing that the argument "row" when parsed into choice_func refers to a row of data from Choice data tab in the sample-data.xlsx and row[0] refers to the first column of Choice tab whose values are e.g. 'ide'. Am i correct? 

        def choice_func(row):
            q = Question.objects.filter(slug=row[0])[0]
            row[0] = q
            return row

sachinbg sachin

unread,
Jul 23, 2019, 10:28:09 AM7/23/19
to django...@googlegroups.com
If ur dumping the data from exel make prepare as per ur database table ur exel headings should be as table name check in models then migrate and make migrate it will work

--
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/e8b0cc85-517b-4452-b856-2c4ff14b8019%40googlegroups.com.

Jasmine Chua

unread,
Jul 23, 2019, 10:46:34 AM7/23/19
to Django users
Thanks for your reply. My excel column headers are the same as my model field names but i am still getting the error as seen.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

sachinbg sachin

unread,
Jul 23, 2019, 10:51:17 AM7/23/19
to django...@googlegroups.com
In exception it it's saying as case sensitive check the fist Peter's wether they are caps are small in model fist leter always bigleter check once

On Tue, Jul 23, 2019, 5:04 PM Jasmine Chua <babym...@gmail.com> wrote:
--
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.

Jasmine Chua

unread,
Jul 23, 2019, 11:21:12 AM7/23/19
to Django users
Sorry may I trouble you to please spell your sentence properly? I am having difficulty understanding what i should check for in terms of case sensitivity.

I suspect that the problem lies in my functions when importing the data into my Models because certain fields are foreign keys i need to import them as object instances instead of data (as seen in the choice_func example in the Django-Excel documentation found here http://django.pyexcel.org/en/latest/). However, i am not sure if i understand the code for choice_func correctly.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages