django import with django-import-export

487 views Asked by At

could anybody tell me what I did wrongly here as I am unable to see all the fields while importing data from db

class UserResource(ModelResource):

    class Meta:
        model = User
        fields = ('username', 'email', 'first_name', 'last_name', 'id')
        import_id_fields = ('id',)


class UserAdmin(ImportMixin, admin.ModelAdmin):
    resource_class = UserResource

As show below ss I can see only username field shows up enter image description here

my csv file is shown below

username, email, first_name, Last_name, id
abc, [email protected], abd, de

and models

class User(AbstractUser):
    trial_period = models.DateTimeField(default=timezone.now)
    on_trial = models.BooleanField(default=False)
    is_approved = models.CharField(max_length=80, choices=APPROVAL_CHOICES, default='t-2')
    paid_until = models.DateTimeField(default=timezone.now)
    is_member = models.BooleanField(default=False)
    is_premium_member = models.BooleanField(default=False)
1

There are 1 answers

2
Matthew Hegarty On

I think this issue could be caused by:

  1. Having the header names in the csv not matching the model attribute names (e.g. 'Last_name' should be 'last_name').

  2. Some undiscovered bug in the library or application code.

Also I notice that your csv row contains 4 fields, but you declare 5 headers (no value is provided for 'id').

Other than that I cannot see any issues. Python 3.8 should be fine.

Please update if you found the source of the problem.