-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorporate with django-import-export #323
Comments
I created a proxy model to work with import-export and let the original model using reversion. Enviada do meu iPhone
|
reichert, could you post some example code on what you did? |
Sure, here it is: models.pyclass Product(models.Model):
class ProductImportExport(Product): admin.py@admin.register(Product) ################################################################################## DJANGO IMPORT EXPORT CLASSES################################################# class ProductResource(resources.ModelResource): @admin.register(ProductImportExport) Alessandro Reichert On Sun, Jul 13, 2014 at 12:51 PM, enj notifications@github.com wrote:
|
I replicated this set up but it does not really work. Now I have one admin |
So I have come up with a working solution using reversion's middleware (though I am sure there is a better way to do this without having to use the middleware): # admin.py
class ExampleAdmin(ImportExportMixin, reversion.VersionAdmin):
resource_class = ExampleResource
# models.py
class Example(models.Model):
date = models.DateField('Date')
stuff = models.ManyToManyField('stuff')
reversion.register(Example, follow=['stuff',])
# resources.py (could be at end of admin.py)
class ExampleResource(resources.ModelResource):
class Meta:
model = Example
def get_or_init_instance(self, instance_loader, row):
# Date's val needs to be a datetime object, not unicode
row['Date'] = datetime.date(*map(int, row['Date'].split('-')))
return super(ExampleResource, self).get_or_init_instance(instance_loader, row)
def after_save_instance(self, instance, dry_run):
if not dry_run:
reversion.set_comment("Imported with import_export.")
# settings.py
MIDDLEWARE_CLASSES = (
'reversion.middleware.RevisionMiddleware',
...
)
IMPORT_EXPORT_USE_TRANSACTIONS = False # Cannot use True with reversion |
How would I go about making reversion work with django-import-export. Currently imported data has no revisions created for it.
The text was updated successfully, but these errors were encountered: