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

Restore FK logic and best way to ignore fields #957

Open
TonisPiip opened this issue Jan 26, 2024 · 4 comments
Open

Restore FK logic and best way to ignore fields #957

TonisPiip opened this issue Jan 26, 2024 · 4 comments

Comments

@TonisPiip
Copy link

Hey, my project has been using this for a while, it's a neat app, but mainly it's being used to generate a changelog, so the the documented use-case, but that's not my question.

I tested this with a registered model which has a 1 to 1 relation on another registered model. I wanted to try out the admin system, when clicking the timestamp in the history I hit this issue: #387
As we have the modified timestamp excluded.

I allowed null values for that field, and it got pasted it for the main model, and then I got the same error when revisions tried to apply a revision to it's 1on1 related row, which has the same field.

Why is it doing that? Meaning; why is reversion applying a reversion to related rows? I can't find anything in the docs about it.

And also in the linked issue above, it was said it's a bad idea to exclude fields, but I wonder, where is that mentioned in the docs, or is there some best practices? Or is there some way to exclude fields, so they are still tracked, but not have the fields be considered when it's checking the logic for ignore_duplicates?

@etianen
Copy link
Owner

etianen commented Jan 27, 2024

Hi @TonisPiip!

From the docs, the admin integration automatically follows some kinds of relation when auto-registering models:

If you’ve registered your models using reversion.register(), the admin class will use the configuration you specify there. Otherwise, the admin class will auto-register your model, following all inline model relations and parent superclasses. Customize the admin registration by overriding VersionAdmin.register().

Following a relation means that relation is always grouped into a a revision whenever the model is saved. Possibly this is what's causing your problems?

There's no current feature to ignore fields as part of the ignore_duplicates check. I'd be happy to take a PR for that feature, as it seems useful!

@TonisPiip
Copy link
Author

Thanks for the pointer for the doc, I do fear that is not the issues, or maybe I'm not understanding it well enough.

The modeladmin which has been registered has no inlines, just a 1on1 field. Is there any logic for restoring that when you restore, and the model as a (FK or 1to1) relation to another registered model, that model also gets restored?

@etianen
Copy link
Owner

etianen commented Jan 29, 2024

Are you using manual @reversion.register() calls for your models?

@TonisPiip
Copy link
Author

Are you using manual @reversion.register() calls for your models?

@etianen Yes.

Is there a better method?

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

No branches or pull requests

2 participants