я получаю сообщение об ошибке:
Номер строки: 1 - аргумент int () должен быть строкой, байтовоподобным объектом или числом, а не 'builtin_function_or_method'
Я пытаюсь получить доступ к идентификатору дочерних моделей для сортировки по экземпляру компании для каждого магазина. Это работает, если я загружаю данные через дочернюю модель, но пытаюсь сделать обратное с ошибками?
model.py
class Parent(models.Model):
store = models.IntegerField(primary_key=True)
state = models.CharField(max_length=250, blank=True)
# pylint: disable=R0903
def __str__(self):
return '{}'.format(self.store)
class Child(models.Model):
id = models.BigIntegerField(primary_key=True)
store = models.ForeignKey('Parent', on_delete=models.CASCADE, null=True)
company = models.CharField(max_length=250, blank=True)
rank = models.IntegerField(blank=True, default='')
# pylint: disable=R0903
def __str__(self):
return '{}'.format(self.company)
admin.py
class ParentResource(resources.ModelResource):
state = fields.Field(attribute='state', column_name='State')
store = fields.Field(attribute='store', column_name='Store')
company = fields.Field(attribute='company', column_name='Company', widget=ForeignKeyWidget(Child, 'company'))
class Meta:
model = Parent
import_id_fields = ('store', 'state',)
fields = ('store', 'state', 'company',)
def before_import_row(self, row, **kwargs):
company = row.get('Company')
store = row.get('Store')
store = Parent.objects.get_or_create(store=store)
rank = row.get('Rank')
company = Child.objects.get_or_create(store=store[0], company=company, rank=rank, id=id)
class ParentAdmin(ImportExportModelAdmin):
inlines = [ChildInline]
resource_class = ParentResource
list_display = ['store', 'state']
class Meta:
model = Parent
полный возврат
Traceback (most recent call last):
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/import_export/resources.py", line 499, in import_row
self.before_import_row(row, **kwargs)
File "/home/developer/boards/cms/money/admin.py", line 69, in before_import_row
company = Child.objects.get_or_create(store=store[0], company=company, rank=rank, id=id)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/query.py", line 486, in get_or_create
return self.get(**lookup), False
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/query.py", line 390, in get
clone = self.filter(*args, **kwargs)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/query.py", line 844, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/query.py", line 862, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1263, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1287, in _add_q
split_subq=split_subq,
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1225, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1096, in build_lookup
lookup = lookup_class(lhs, rhs)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/lookups.py", line 20, in __init__
self.rhs = self.get_prep_lookup()
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/lookups.py", line 70, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "/home/developer/.local/share/virtualenvs/cms-JnJjjKhL/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 965, in get_prep_value
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'