import error, 'get() keywords must be strings'
See original GitHub issueI’m having trouble getting a form to accept data on import. Currently testing csv
format file; get same errors with xls
file.
sample from import.csv:
jid,project_code,collab_id,sample_code,sequencing_type
JMQN3H,AAST,42567,ST,1
JO2FT1,AAST,43267,ST,1
The error coming out is get() keywords must be strings
.
django error log:
Line number: 1 - get() keywords must be strings
OrderedDict([('jid', 'JMQN3H'), ('project_code', 'AAST'), ('collab_id', '42567'), ('sample_code', 'ST'), ('sequencing_type', '1')])
Traceback (most recent call last):
File "/var/www/django/jid_generator/lib/python3.4/site-packages/import_export/resources.py", line 356, in import_data
instance, new = self.get_or_init_instance(instance_loader, row)
File "/var/www/django/jid_generator/lib/python3.4/site-packages/import_export/resources.py", line 186, in get_or_init_instance
instance = self.get_instance(instance_loader, row)
TypeError: get() keywords must be strings
I tried putting the values in csv file inside quotes.
I tried modifying the admin
, form
and the Resource
widgets.
admin.py:
"""ImportExport Resource"""
class DetailResource(resources.ModelResource):
jid = fields.Field(
default=generate_Jid(prefix='J'),
readonly=True,
widget=widgets.CharWidget(),
)
project_code = fields.Field(column_name='project_code', attribute='project_code',
widget=widgets.ForeignKeyWidget(ProjectCode, 'code'),
)
sample_type = fields.Field(
widget=widgets.ForeignKeyWidget(SampleType, 'code'),
)
sequencing_type = fields.Field(
widget=widgets.ForeignKeyWidget(SequencingType, 'code'),
)
collab_id = fields.Field(
widget=widgets.CharWidget(),
)
class Meta:
model = JIdDetail
all_fields = ( 'jid', 'project_code', 'collab_id',
'sample_type', 'sequencing_type', )
import_id_fields = ( 'jid', )
fields = all_fields
export_order = all_fields
@admin.register(JIdDetail)
# class JIdDetailAdmin(admin.ModelAdmin):
class JIdDetailAdmin(ImportExportModelAdmin):
resource_class = DetailResource
# has_add_permission removes the individual 'add' admin action
# def has_add_permission(self, request):
# return False
form = JIdDetailForm
actions_on_top = False
actions = None
all_fields = ( 'jid', 'project_code', 'collab_id',
'sample_type', 'sequencing_type', )
fields = ( all_fields, )
list_display = all_fields
search_fields = all_fields
readonly_fields = ( 'jid' ),
list_filter = ( 'sample_type', 'sequencing_type', 'project_code' )
ordering = ['creation_date', 'project_code', 'sequencing_type']
forms.py:
class JIdDetailForm(forms.ModelForm):
class Meta:
model = JIdDetail
fields = ( 'jid', 'project_code', 'collab_id',
'sample_type', 'sequencing_type', )
readonly_fields = ( 'jid' ),
# widgets = {
# 'jid': forms.TextInput(attrs={'size':'6'}),
# 'collab_id': forms.TextInput(attrs={'size':'40'}),
# }
models.py
class JIdDetail(models.Model):
verbose_name = 'J Id Detail'
jid = models.CharField('J ID',
max_length=6, blank=False,
help_text="A unique ID string for every sample.",
unique=True,
)
project_code = models.ForeignKey(ProjectCode, to_field='code')
collab_id = models.TextField('Collaborator ID', blank=False,
help_text="Collaborator sample ID."
)
sample_type = models.ForeignKey(SampleType, to_field='code')
sequencing_type = models.ForeignKey(SequencingType, to_field='code')
creation_date = models.DateTimeField(auto_now_add=True)
Any tips on how to troubleshoot this?
Thanks! -Benjamin-
Issue Analytics
- State:
- Created 8 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
python 3.x - get() keywords must be strings - Stack Overflow
get() keywords must be strings I was able to upload files through django import export but now I am not able to...
Read more >filter() keywords must be strings - Django's bug tracker
When using Many2Many fields with unicode data, it raises “TypeError: filter() keywords must be strings” on <model>. <m2m>. all(). The solution is same...
Read more >[Solved]-get() keywords must be strings-django
Coding example for the question get() keywords must be strings-django. ... When upgrading from Django 1.7 - 1.8, I get ImportError: Could not...
Read more >BuiltIn library | Robocorp documentation
This keyword works with Python strings and lists and all objects that either have count method or can be converted to Python lists....
Read more >Robot Framework User Guide
Keywords can be imported from test libraries or resource files, ... Test Cases *** String ${string} = Set Variable abc Log ${string.upper()} #...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Works very well! Thanks for your assistance! It’s all in the
attribute
’s. Need to search docs for them and figure out what they’re used for now. 😃Glad it works for you, please open new issue if needed.