Comments (15)
That's my full project
model:
from djmoney.models.fields import MoneyField
from smart_selects.db_fields import ChainedForeignKey
class Project(models.Model):
STATUS_CHOICES = [
[...]
]
STAGE_CHOICES = [
[...]
]
title = models.CharField(max_length=200)
project_number = models.DecimalField(max_digits=15, decimal_places=0, blank=True, null=True)
funder = models.ForeignKey(Funder, on_delete=models.PROTECT, null=True, blank=True)
scheme = ChainedForeignKey(
Scheme,
chained_field="funder",
chained_model_field="funders",
show_all=False,
auto_choose=True,
sort=True, null=True, blank=True)
application_stage = models.CharField(choices=STAGE_CHOICES, max_length=30, null=True, blank=True)
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
status = models.CharField(choices=STATUS_CHOICES, max_length=30, null=True, blank=True)
submitted_on = models.DateField(blank=True, null=True)
budget = MoneyField(max_digits=14, decimal_places=2, default_currency='GBP', null=True, blank=True)
added_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.PROTECT)
added_on = models.DateField(auto_now_add=True)
person = models.ManyToManyField(Person, through=PersonRole)
collaboration = models.ManyToManyField(Organisation, through=CollaborationType, blank=True)
notes = models.TextField(blank=True, null=True)
funder_reference = models.CharField(max_length=15, blank=True, null=True)
def __str__(self):
return self.title
@admin.display(description='Principal investigator')
def get_PI(self):
return [p for p in self.person.filter(personrole__person_role__contains="Principal investigator")]
@admin.display(description='PI School')
def get_PI_school(self):
return [
p.get_PI_school()
for p in self.personrole_set.filter(
person_role__contains="Principal investigator"
)
]
@admin.display(description='PI Subject')
def get_PI_subject(self):
return [
p.get_PI_subject()
for p in self.personrole_set.filter(
person_role__contains="Principal investigator"
)
]
@admin.display(description='Partner') #currently not used
def get_Partner(self):
return [partner for partner in self.collaboration.filter(collaborationtype__collaboration_type__contains="Partner")]
class Meta:
verbose_name_plural = "Projects"
from django-import-export.
Presumably ChainedForeignKey
comes from this project.
from django-import-export.
Hello @matthewhegarty , I can confirm that the issue is with the ChainedForeignKey
field. It was working with version 3.8.
from django-import-export.
That worked, thanks! 👍
from django-import-export.
Thanks for confirming
from django-import-export.
Thanks for raising. Is it possible you can test with #1805 and see if that resolves the issue.
from django-import-export.
Thank you. I now get the following:
Traceback (most recent call last):
File "/opt/team_django/./manage.py", line 22, in <module>
main()
File "/opt/team_django/./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/core/management/__init__.py", line 416, in execute
django.setup()
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/apps.py", line 27, in ready
self.module.autodiscover()
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/contrib/admin/__init__.py", line 52, in autodiscover
autodiscover_modules("admin", register_to=site)
File "/usr/local/py_ptracker/lib/python3.11/site-packages/django/utils/module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/opt/team_django/artsdb/admin.py", line 153, in <module>
class ProjectResource(resources.ModelResource):
File "/usr/local/py_ptracker/lib/python3.11/site-packages/import_export/declarative.py", line 100, in __new__
field = new_class.field_from_django_field(f.name, f, readonly=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py_ptracker/lib/python3.11/site-packages/import_export/resources.py", line 1289, in field_from_django_field
widget=FieldWidget(**widget_kwargs),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'str' object is not callable
from django-import-export.
ok - is it possible you can give me some steps to reproduce? Can you identify which field in ProjectResource
is causing the issue?
from django-import-export.
I have this in admin.py
:
from import_export import resources
from import_export.admin import ImportExportModelAdmin
class ProjectResource(resources.ModelResource):
class Meta:
model = Project
class ProjectAdmin(ImportExportModelAdmin):
resource_classes = [ProjectResource]
from django-import-export.
How can I identify the problematic field? Do I need to comment them one by one?
from django-import-export.
Are you able to post the field list for the Project
model class?
from django-import-export.
Do you want me to comment that field? It was working before upgrading to 4.0.
from django-import-export.
If you could try that it would be appreciated. It would be ideal to identify which of your fields is causing the issue.
from django-import-export.
OK, I'll make a full database backup and comment the fields one by one.
from django-import-export.
ok thanks. If it's easier and safer, you could use the example app and add fields from other packages. My guess is that it will be the ChainedForeignKey
or MoneyField
which is the issue. This is probably what I will end up doing, but if you can look into it, then it will speed up a resolution.
from django-import-export.
Related Issues (20)
- Can't import file without an `id` column in V4 HOT 4
- v4 add custom delimiter for csv. HOT 5
- Referencing a column alias in the `fields` list causes a crash on import HOT 1
- `use_natural_foreign_keys` in ModelResource.Meta not working in V4 HOT 2
- Why always assume the model going have id as primary key? why can not we dynamically get PK field from model? HOT 11
- Lost all the default import and export options after upgrading to V4 HOT 2
- Default field set differs during import in v4 HOT 3
- `resource_class` was deprecated and removed, but it still works HOT 2
- Export crashes if the column name is used instead of the attribute name
- Resource field is empty when importing data HOT 5
- Fixed Arabic translate for 'Import' word HOT 2
- Breaking change due to _check_import_id_fields HOT 2
- Improve parsing of DateTimeWidget HOT 4
- `TypeError: Widget.__init__() got an unexpected keyword argument 'allow_blank'` HOT 4
- numeric fields exported as text by default since v4 to excel HOT 4
- Customize export format depending on file type
- ModelResource field order in admin import page HOT 5
- Exporting fields with changed `column_name` doesn't work in v4 HOT 5
- How to explicitly disable and enable bulk import? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-import-export.