How İs it possible apply filtering to the imported data while using django-import-export package

By applying Form (not using Admin Panel) it is possible for users to import their data in xlsx format to the models practically. I have two models Task & Item. Each Task object has many Item objects in it. When it is intended to import a data file which includes mixed data, namely more than one tasks created by different user with their items, Django-import-export utility import all of them. But in some cases it is required to limit the import process by allowing the tasks which are created by the user itself and not whole task data. Can I overcome this issue by appling filter to data?

def importData(request,pk):
if request.method == 'POST':
    #query = Item.objects.filter(task_id = pk)
    item_resource = ItemResource()
    dataset = Dataset()
    new_items = request.FILES['importData']
    imported_data = dataset.load(, format='xlsx')
    result = item_resource.import_data(dataset, dry_run=True)

    if not result.has_errors():
        item_resource.import_data(dataset, dry_run=False)

        converted = str(pk)
        return HttpResponseRedirect(''+'checklist/task/'+ converted + '/')
        return HttpResponse('Your Data is not Proper ! Please Try Again...')

return render(request, 'checklist/import.html')enter code here
class Task(models.Model):
    user = models.ForeignKey(User, verbose_name="Kullanıcı", on_delete=models.CASCADE, null=True, blank=True)
    title = models.CharField(verbose_name="Kontrol Listesi Başlığı", max_length=200)
    description = models.TextField(verbose_name="Açıklama", null=True, blank=True)
    complete = models.BooleanField(verbose_name="Tamamlandı mı?", default=False)
    created = models.DateTimeField(auto_now_add=True, verbose_name='Kayıt Tarihi')
    update_date = models.DateTimeField(auto_now=True, verbose_name='Son Güncelleme')

class Item(models.Model):
    task = models.ForeignKey(Task, verbose_name="Kontrol Listesi", on_delete=models.CASCADE)
    measure = models.CharField(verbose_name="Kontrol Faaliyeti (Önlem)", max_length=250)
    status = models.CharField(verbose_name='Uygun mu?', default='Y', max_length=20, choices = STATUS_CHOICES)
    note = models.CharField(verbose_name='Notlar', max_length=150, null=True, blank=True)

urlpatterns = [
    path('checklist/export/task/<int:pk>/',exportData, name='export-data'),
    path('checklist/import/task/<int:pk>/',importData, name='import-data'),

Back to Top