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

Reorder management command per #188 #240

Merged
merged 8 commits into from Apr 14, 2021
Merged

Conversation

shuckc
Copy link
Member

@shuckc shuckc commented Apr 8, 2021

The great work from #188 by @flupzor with a couple of small fixups

Alexander Schrijver and others added 4 commits April 13, 2021 22:26
…me reason the ordering was corrupted.

In certain cases the models will end up in a not properly ordered state. This can be caused
by bypassing the 'delete' / 'save' methods, or when a user changes a foreign key of a object
which is part of the 'order_with_respect_to' fields.

This management command allows you to repair this invalid state.
@shuckc shuckc force-pushed the reorder-management-command branch from e15e310 to 56b75b6 Compare April 13, 2021 21:27
@shuckc shuckc force-pushed the reorder-management-command branch from 3932690 to a5f305c Compare April 14, 2021 10:34
@shuckc
Copy link
Member Author

shuckc commented Apr 14, 2021

Runing the reorder_model management command manually over all of our test models now fails only with tests.Answer since we lack support for multiple fields in order_with_respect_to:

~/django-ordered-model$ django-admin reorder_model --pythonpath=. --settings=tests.settings --skip-checks tests.Answer
Traceback (most recent call last):
  File "/home/chris/django-ordered-model/venv/bin/django-admin", line 8, in <module>
    sys.exit(execute_from_command_line())
  File "/home/chris/django-ordered-model/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/chris/django-ordered-model/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/chris/django-ordered-model/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/chris/django-ordered-model/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "./ordered_model/management/commands/reorder_model.py", line 54, in handle
    self.reorder(model)
  File "./ordered_model/management/commands/reorder_model.py", line 58, in reorder
    order_with_respect_to = get_order_with_respect_to(model)
  File "./ordered_model/management/commands/reorder_model.py", line 13, in get_order_with_respect_to
    assert (
AssertionError: re-ordering with more than 1 fields in order_with_respect_to is not supported

I would rather keep this as an NYI since there is (great) utility in merging this.

@imomaliev
Copy link
Collaborator

I would rather keep this as an NYI since there is (great) utility in merging this.

I think this is ok for now

@shuckc
Copy link
Member Author

shuckc commented Apr 14, 2021

I've pushed the bulk_update patch discussed #240 (comment) to branch origin/patch_reorder_after_dj22 so if anyone needs it and is on Django > 2.2 they can apply it.

@shuckc shuckc merged commit 109192e into master Apr 14, 2021
@shuckc shuckc deleted the reorder-management-command branch March 7, 2023 07:37
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

Successfully merging this pull request may close these issues.

None yet

2 participants