4๐
I had a similar problem.
It is that for import django import-export uses โidโ by default.
First, create a resources.py file โ where you will declare settings for import and export. And as an exception, declare โidโ.
resources.py
from import_export import resources
from .models import *
class PropertyAdminResource(resources.ModelResource):
class Meta:
model = PropertyModel
exclude = ('id',)
admin.py
from .resources import *
@admin.register(PropertyModel)
class PropertyAdmin(ImportExportModelAdmin):
resource_class = PropertyAdminResource
list_display = ['Property_ID', 'Created_By', 'Last_Updated_By']
I highly recommend using resources.py โ where you can modify the methods for import and export.
1๐
you need to let the resources model know your primary key, if it didnโt find it will automatically set it to โidโ
here is an example
models.py
class Product(models.Model):
my_id = models.CharField(max_length=255, primary_key=True)
admin.py
from import_export.admin import ImportExportModelAdmin
from import_export import resources
class ProductAdminResource(resources.ModelResource):
class Meta:
model = Product
import_id_fields = ['my_id']
@admin.register(Product)
class ProductAdminView(ImportExportModelAdmin):
resource_class = ProductAdminResource
- [Django]-Django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured
- [Django]-Tastypie-nonrel, django, mongodb: too many nestings
- [Django]-How to unittest "new style" Django middleware
0๐
I had some errors like you and managed to solve them following this answer โ https://github.com/django-import-export/django-import-export/issues/92#issuecomment-598009569
I changed from version 2.0.2 to 2.0.1, removed the custom primary key and migrated again
I hope this helps with your problem
- [Django]-Django admin โ how to display thumbnail instead of path to file
- [Django]-How to check if a queryset is empty?
0๐
Please read
https://django-import-export.readthedocs.io/en/latest/getting_started.html#customize-resource-options
So for your your model you could do
class PropertyAdminResource(resources.ModelResource):
class Meta:
model = PropertyModel
import_id_fields = ('Property_ID',)
class PropertyModelAdmin(ImportExportModelAdmin):
resource_class = PropertyAdminResource
admin.site.register(PropertyModel, PropertyModelAdmin)
tested with django-import-export 2.7.0
- [Django]-Django ORM query with exclude not working properly
- [Django]-Django Rest framework: passing request object around makes it lose POST data in newer version