# Django Import Export data without ID

**URL:** <https://forum.djangoproject.com/t/django-import-export-data-without-id/14326>\
**Category:** Forms & APIs\
**Created:** [June 16, 2022, 8:42pm UTC](https://forum.djangoproject.com/t/django-import-export-data-without-id/14326 "2022-06-16T20:42:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingman29](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kingman29/32/8853_2.png) [@kingman29](https://forum.djangoproject.com/u/kingman29)\
**Post date:** [June 16, 2022, 8:42pm UTC](https://forum.djangoproject.com/t/django-import-export-data-without-id/14326/1 "2022-06-16T20:42:17Z")

</div>

I tried to export data from Django to Excel, but every thing walk behind me, when I export a Excel File, Django Export only Ids :  
 ![id problem](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/7/7e3295bdb22d9935361a5b22c8ffd4b472ade1f4.png)  
**all what I need is export Data and replace id with Column I choose.**  
**I want to export Data (ex : name of rooms , name of Person**

I tried to walk behind some tutorials like :  
[https://django-import-export.readthedocs.io/en/latest/api\_widgets.html](https://django-import-export.readthedocs.io/en/latest/api_widgets.html)  
and  
[https://stackoverflow.com/questions/59937531/django-call-id-expected-a-number-but-got-string.](https://stackoverflow.com/questions/59937531/django-call-id-expected-a-number-but-got-string.)

In Django App, I have:  
models.py

```auto

    from pyexpat import model
    from statistics import mode
    from django.db import models
    from django.contrib.auth.models import User
    from django.db.models.base import Model
    from django.forms import IntegerField

    class Post(models.Model):
        name = models.CharField(max_length=150)

        def __str__ (self):
            return str(self.name)

    class Person(models.Model):
        post = models.ForeignKey(Post, on_delete=models.CASCADE)
        name = models.CharField(max_length=100)

        def __str__ (self):
            return f"({self.name} is {self.post} "

    class Room(models.Model):
        name = models.CharField(max_length= 150 )

        def __str__ (self):
            return str(self.name)

    class Classification(models.Model):
        name = models.ForeignKey(Person, on_delete=models.CASCADE)
        room = models.ForeignKey(Room, on_delete=models.CASCADE)
        date = models.DateField(auto_created=False)

        def __str__ (self):
            return f"({self.name} Take {self.room} at {self.date})"

```

admin.py

```auto

        from django.contrib import admin
        from import_export.admin import ImportExportModelAdmin
        from .models import *
        from import_export import fields, resources
        from import_export.widgets import ForeignKeyWidget

    @admin.register(Post, Room, Classification, Person)
    class TestappImportExport(ImportExportModelAdmin):
        pass

    class Classificationresource(resources.ModelResource):
        name = fields.Field(
            column_name='name',
            attribute='name',
            widget=ForeignKeyWidget(Person, 'name'))

        room = fields.Field(
            column_name = 'room',
            attribute = 'room',
            widget= ForeignKeyWidget(Room, 'name'))

        class Meta:
            fields = ('name', 'room')

```

even I tried to reverse class Classificationresource(resources.ModelResource) up of Classificationresource(resources.ModelResource), and I still get ids and not the name of Persons or Rooms.

So please help me to solve this problem, I tired to stay searching and I feel that I spend a time for that.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 17, 2022, 1:01am UTC](https://forum.djangoproject.com/t/django-import-export-data-without-id/14326/2 "2022-06-17T01:01:12Z")

</div>

See the last example in the docs at [Getting started — django-import-export 2.8.1.dev0 documentation](https://django-import-export.readthedocs.io/en/latest/getting_started.html#customize-resource-options)

You should be able to use the ORM-style field references in the fields attribute of the Meta class in your ModelResources class.

For example, you should be able to use `name__name` to follow the foreign key relationship from the Classification object to the related Person object, to retrieve the name field of that Person object.

---

<div class="post-metadata">

**Author:** ![kingman29](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kingman29/32/8853_2.png) [@kingman29](https://forum.djangoproject.com/u/kingman29)\
**Post date:** [June 17, 2022, 12:01pm UTC](https://forum.djangoproject.com/t/django-import-export-data-without-id/14326/3 "2022-06-17T12:01:36Z")

</div>

I tried this in admin.py:

```auto
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from .models import *
from import_export import fields, resources
from import_export.widgets import ForeignKeyWidget

@admin.register(Post, Room, Classification, Person)
class TestappImportExport(ImportExportModelAdmin):
    pass

class Classificationresource(resources.ModelResource):
    name = fields.Field(
        column_name='name',
        attribute='name',
        widget=ForeignKeyWidget(Person, 'name')
    )

    room = fields.Field(
        column_name = 'room',
        attribute = 'room',
        widget= ForeignKeyWidget(Room, 'name'))

    
    class Meta:
        fields = ('id', 'name __name', 'room__ name', 'date')

```

even this, it still export data with id

```auto
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from .models import *
from import_export import fields, resources
from import_export.widgets import ForeignKeyWidget

@admin.register(Post, Room, Classification, Person)
class TestappImportExport(ImportExportModelAdmin):
    pass

class Classificationresource(resources.ModelResource):

    
    class Meta:
        model = Classification
        fields = ('id', 'name __name', 'room__ name', 'date')

```

---

<div class="post-metadata">

**Author:** ![kingman29](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kingman29/32/8853_2.png) [@kingman29](https://forum.djangoproject.com/u/kingman29)\
**Post date:** [June 17, 2022, 7:54pm UTC](https://forum.djangoproject.com/t/django-import-export-data-without-id/14326/4 "2022-06-17T19:54:48Z")

</div>

I get the solution with this :

```auto
class Classificationresource(resources.ModelResource):

    class Meta:
        model = Classification
        fields = ('id', 'name __name', 'room__ name', 'date')

```

```auto
@admin.register(Classification) 
class TestappImportExport(ImportExportModelAdmin): 
    resource_class = Classificationresource

```
