mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #34420 -- Corrected the order of imports in generated migration files.
This commit is contained in:
committed by
Mariusz Felisiak
parent
0eb3e9bd75
commit
b295b31171
@@ -175,7 +175,10 @@ class MigrationWriter:
|
||||
|
||||
# Sort imports by the package / module to be imported (the part after
|
||||
# "from" in "from ... import ..." or after "import" in "import ...").
|
||||
sorted_imports = sorted(imports, key=lambda i: i.split()[1])
|
||||
# First group the "import" statements, then "from ... import ...".
|
||||
sorted_imports = sorted(
|
||||
imports, key=lambda i: (i.split()[0] == "from", i.split()[1])
|
||||
)
|
||||
items["imports"] = "\n".join(sorted_imports) + "\n" if imports else ""
|
||||
if migration_imports:
|
||||
items["imports"] += (
|
||||
|
||||
Reference in New Issue
Block a user