Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Export with Foreignkey #18

Closed
resakse opened this issue Apr 19, 2016 · 2 comments
Closed

Custom Export with Foreignkey #18

resakse opened this issue Apr 19, 2016 · 2 comments

Comments

@resakse
Copy link

resakse commented Apr 19, 2016

def export_data(request, atype):
....
elif atype == "custom":
question = Question.objects.get(slug='ide')
query_sets = Choice.objects.filter(question=question)
column_names = ['choice_text', 'id', 'votes']
sheet = excel.pe.get_sheet(query_sets=query_sets, column_names=column_names)
sheet.row[0] = ["X", "Y", "Z"] # please put verbose_name list here
return excel.make_response(sheet, 'xls')

while that code works fine, but it failed when I tried to include question it self

def export_data(request, atype):
....
elif atype == "custom":
question = Question.objects.get(slug='ide')
query_sets = Choice.objects.filter(question=question)
column_names = ['question','choice_text', 'votes']
sheet = excel.pe.get_sheet(query_sets=query_sets, column_names=column_names)
sheet.row[0] = ["Question", "Choice", "Votes"] # please put verbose_name list here
return excel.make_response(sheet, 'xls')

would return me Unexpected data type

but if I were to replace column_names to
`
column_names = ['question__question_text','choice_text', 'votes']

`
it would returns me :

'Choice' object has no attribute 'question__question_text'

is there anyway to do this?

thanks!

@chfw
Copy link
Member

chfw commented Apr 20, 2016

At your first attempt, a instance of polls.models.Question was obtained at line 180 and at the second one, line 180 would not get "question__question_text" from Choice.

There is a way definitely. One thought I had is to check if the value is a field or a foreign key to another model. If the value is the latter case, maybe put a str() around it to get its representation. The ideal case would be to support 'question__question_text' at L180. let me have a look.

@chfw
Copy link
Member

chfw commented Jul 14, 2016

please retry with latest pyexcel and pyexcel-io. 'question__question_text' is now recognized as foreign key.

@chfw chfw closed this as completed Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants