question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with ForeignKeyWidget

See original GitHub issue

I’m following the docs on ForeignKeyWidget very closely, and am still getting an error when uploading an Excel file. My resource looks like this:

class AssignmentResource(resources.ModelResource):
	instruction_type = fields.Field(
		column_name='instruction_type',
		attribute='instruction_type',
		widget=ForeignKeyWidget(InstructionType, 'type')
	)

	class Meta:
		model = Assignment
		fields = ('instruction_type',)

type is a string field on the InstructionType model. When I try to upload a spreadsheet that has string values, I get this error:

Line number: 1 - Column 'instruction_type': invalid literal for int() with base 10: 'Research'

What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
GregKalekacommented, Mar 14, 2018

🤦‍

So… I never actually added the line resource_class = AssignmentResource to my AssignmentAdmin class.

Sorry for the runaround!

1reaction
sometimescaseycommented, Jun 9, 2021

🤦‍

So… I never actually added the line resource_class = AssignmentResource to my AssignmentAdmin class.

Sorry for the runaround!

I told myself I couldn’t possibly have forgotten this and lo and behold I checked and…I also forgot to do this. THANK YOU!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve MultipleObjectsReturned with ForeignKeywidget ...
Jaq / class 2 Lucy / class 2 # only 1 can have 2 as its a ForeignKey # same error will happen...
Read more >
Problem with ForeignKeyWidget - - Bountysource
I'm following the docs on ForeignKeyWidget very closely, and am still getting an error when uploading an Excel file. My resource looks like...
Read more >
Adding foreignKey widget to django-import-export - YouTube
Django : Adding foreignKey widget to django-import-export [ Beautify Your ... If there any issues, contact us on - htfyc dot hows dot...
Read more >
Widgets — django-import-export 3.0.3.dev0 documentation
…using a ForeignKeyWidget has the advantage that it can not only be used for exporting, but also importing data with foreign key relationships....
Read more >
django-import-export ForeignKeyWidget : r/django - Reddit
I can not get the ForeignKeyWidget to work when importing in the admin ... r/StableDiffusion - ModuleNotFoundError: No module named 'frontend' error in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found