0
votes

I'm using Django import-export in the admin for my app but I can't find any examples of what I think must be a common use case.

In my Author admin page I would like an "Export all books written by this author" admin action which exports all books written by the author. Any help would be appreciated.

I could simply create a new Django admin action but I would really like to keep the awesome import-export 'select format' dropdown list.

class Author(models.Model):
    name = models.CharField(max_length=100)

    def __unicode__(self):
        return self.name


class Book(models.Model):
    name = models.CharField('Book name', max_length=100)
    author = models.ForeignKey(Author, blank=True, null=True)
    author_email = models.EmailField('Author email', max_length=75, blank=True)
    imported = models.BooleanField(default=False)
    published = models.DateField('Published', blank=True, null=True)
    price = models.DecimalField(max_digits=10, decimal_places=2, null=True,
            blank=True)

    def __unicode__(self):
        return self.name
1

1 Answers

1
votes

You could put the export action in the Book admin and add a filter for author. You'll then be able to filter the books by a single author and export the results.