Skip to content
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

Modify model instance with post_import signal #1250

Open
philmcnamara opened this issue Mar 12, 2021 · 1 comment
Open

Modify model instance with post_import signal #1250

philmcnamara opened this issue Mar 12, 2021 · 1 comment
Labels

Comments

@philmcnamara
Copy link

Hi all,

I would like to make some modifications to imported data using the _post_import signal.

My code looks like this:

class OligoImportResource(resources.ModelResource):

    created_by = fields.Field(
        column_name='created_by',
        attribute='created_by',
        widget=ForeignKeyWidget(User, field='username')
    )

    class Meta:
        model = Oligo
@receiver(post_import, dispatch_uid="modify_import")
def _post_import(model, **kwargs):
    model.comment= "extra comment"
    model.save()

Based on the documentation the model argument should be giving me an instance of my model, but when I try to confirm import I get the following error:

save() missing 1 required positional argument: 'self'

I would also like to access request to get the user id during import which someone else here mentioned was possible using kwargs but I can't get that to work either. Any help is appreciated.

@tochimclaren
Copy link

tochimclaren commented Mar 13, 2021

My problem is that _post_import signal is not being called.


@receiver(post_import, dispatch_uid='balabala...')
def _post_import(model, **kwargs):
# model is the actual model instance which after import
print(model)
`

after succesful import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants