Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- testbed/django__django/.editorconfig +47 -0
- testbed/django__django/.eslintignore +7 -0
- testbed/django__django/.eslintrc +37 -0
- testbed/django__django/.git-blame-ignore-revs +9 -0
- testbed/django__django/.gitattributes +7 -0
- testbed/django__django/.gitignore +18 -0
- testbed/django__django/.pre-commit-config.yaml +24 -0
- testbed/django__django/.readthedocs.yml +18 -0
- testbed/django__django/AUTHORS +1073 -0
- testbed/django__django/CONTRIBUTING.rst +32 -0
- testbed/django__django/Gruntfile.js +15 -0
- testbed/django__django/INSTALL +8 -0
- testbed/django__django/LICENSE +27 -0
- testbed/django__django/LICENSE.python +290 -0
- testbed/django__django/MANIFEST.in +17 -0
- testbed/django__django/README.rst +58 -0
- testbed/django__django/package.json +19 -0
- testbed/django__django/pyproject.toml +7 -0
- testbed/django__django/setup.cfg +69 -0
- testbed/django__django/setup.py +55 -0
- testbed/django__django/tests/.coveragerc +16 -0
- testbed/django__django/tests/README.rst +10 -0
- testbed/django__django/tests/model_fields/test_field_flags.py +221 -0
- testbed/django__django/tests/model_fields/test_filepathfield.py +22 -0
- testbed/django__django/tests/model_fields/test_foreignkey.py +169 -0
- testbed/django__django/tests/model_fields/test_jsonfield.py +1144 -0
- testbed/django__django/tests/model_fields/tests.py +376 -0
- testbed/django__django/tests/model_forms/__init__.py +0 -0
- testbed/django__django/tests/model_forms/models.py +523 -0
- testbed/django__django/tests/model_forms/test_uuid.py +35 -0
- testbed/django__django/tests/model_forms/tests.py +0 -0
- testbed/django__django/tests/model_formsets/__init__.py +0 -0
- testbed/django__django/tests/model_formsets/models.py +265 -0
- testbed/django__django/tests/model_formsets/test_uuid.py +117 -0
- testbed/django__django/tests/model_formsets/tests.py +2367 -0
- testbed/django__django/tests/model_formsets_regress/__init__.py +0 -0
- testbed/django__django/tests/model_formsets_regress/tests.py +586 -0
- testbed/django__django/tests/model_indexes/__init__.py +0 -0
- testbed/django__django/tests/model_indexes/models.py +39 -0
- testbed/django__django/tests/model_indexes/tests.py +372 -0
- testbed/django__django/tests/model_inheritance/__init__.py +0 -0
- testbed/django__django/tests/model_inheritance/models.py +214 -0
- testbed/django__django/tests/model_inheritance/test_abstract_inheritance.py +449 -0
- testbed/django__django/tests/model_inheritance/tests.py +670 -0
- testbed/django__django/tests/model_inheritance_regress/__init__.py +0 -0
- testbed/django__django/tests/model_inheritance_regress/models.py +207 -0
- testbed/django__django/tests/model_inheritance_regress/tests.py +676 -0
- testbed/django__django/tests/model_meta/__init__.py +0 -0
- testbed/django__django/tests/model_meta/models.py +183 -0
- testbed/django__django/tests/model_meta/results.py +895 -0
testbed/django__django/.editorconfig
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# https://editorconfig.org/
|
| 2 |
+
|
| 3 |
+
root = true
|
| 4 |
+
|
| 5 |
+
[*]
|
| 6 |
+
indent_style = space
|
| 7 |
+
indent_size = 4
|
| 8 |
+
insert_final_newline = true
|
| 9 |
+
trim_trailing_whitespace = true
|
| 10 |
+
end_of_line = lf
|
| 11 |
+
charset = utf-8
|
| 12 |
+
|
| 13 |
+
# Docstrings and comments use max_line_length = 79
|
| 14 |
+
[*.py]
|
| 15 |
+
max_line_length = 88
|
| 16 |
+
|
| 17 |
+
# Use 2 spaces for the HTML files
|
| 18 |
+
[*.html]
|
| 19 |
+
indent_size = 2
|
| 20 |
+
|
| 21 |
+
# The JSON files contain newlines inconsistently
|
| 22 |
+
[*.json]
|
| 23 |
+
indent_size = 2
|
| 24 |
+
insert_final_newline = ignore
|
| 25 |
+
|
| 26 |
+
[**/admin/js/vendor/**]
|
| 27 |
+
indent_style = ignore
|
| 28 |
+
indent_size = ignore
|
| 29 |
+
|
| 30 |
+
# Minified JavaScript files shouldn't be changed
|
| 31 |
+
[**.min.js]
|
| 32 |
+
indent_style = ignore
|
| 33 |
+
insert_final_newline = ignore
|
| 34 |
+
|
| 35 |
+
# Makefiles always use tabs for indentation
|
| 36 |
+
[Makefile]
|
| 37 |
+
indent_style = tab
|
| 38 |
+
|
| 39 |
+
# Batch files use tabs for indentation
|
| 40 |
+
[*.bat]
|
| 41 |
+
indent_style = tab
|
| 42 |
+
|
| 43 |
+
[docs/**.txt]
|
| 44 |
+
max_line_length = 79
|
| 45 |
+
|
| 46 |
+
[*.yml]
|
| 47 |
+
indent_size = 2
|
testbed/django__django/.eslintignore
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
**/*.min.js
|
| 2 |
+
**/vendor/**/*.js
|
| 3 |
+
django/contrib/gis/templates/**/*.js
|
| 4 |
+
django/views/templates/*.js
|
| 5 |
+
docs/_build/**/*.js
|
| 6 |
+
node_modules/**.js
|
| 7 |
+
tests/**/*.js
|
testbed/django__django/.eslintrc
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"rules": {
|
| 3 |
+
"camelcase": ["off", {"properties": "always"}],
|
| 4 |
+
"comma-spacing": ["error", {"before": false, "after": true}],
|
| 5 |
+
"curly": ["error", "all"],
|
| 6 |
+
"dot-notation": ["error", {"allowKeywords": true}],
|
| 7 |
+
"eqeqeq": ["error"],
|
| 8 |
+
"indent": ["error", 4],
|
| 9 |
+
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
|
| 10 |
+
"linebreak-style": ["error", "unix"],
|
| 11 |
+
"new-cap": ["off", {"newIsCap": true, "capIsNew": true}],
|
| 12 |
+
"no-alert": ["off"],
|
| 13 |
+
"no-eval": ["error"],
|
| 14 |
+
"no-extend-native": ["error", {"exceptions": ["Date", "String"]}],
|
| 15 |
+
"no-multi-spaces": ["error"],
|
| 16 |
+
"no-octal-escape": ["error"],
|
| 17 |
+
"no-script-url": ["error"],
|
| 18 |
+
"no-shadow": ["error", {"hoist": "functions"}],
|
| 19 |
+
"no-underscore-dangle": ["error"],
|
| 20 |
+
"no-unused-vars": ["error", {"vars": "local", "args": "none"}],
|
| 21 |
+
"no-var": ["error"],
|
| 22 |
+
"prefer-const": ["error"],
|
| 23 |
+
"quotes": ["off", "single"],
|
| 24 |
+
"semi": ["error", "always"],
|
| 25 |
+
"space-before-blocks": ["error", "always"],
|
| 26 |
+
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
|
| 27 |
+
"space-infix-ops": ["error", {"int32Hint": false}],
|
| 28 |
+
"strict": ["error", "global"]
|
| 29 |
+
},
|
| 30 |
+
"env": {
|
| 31 |
+
"browser": true,
|
| 32 |
+
"es6": true
|
| 33 |
+
},
|
| 34 |
+
"globals": {
|
| 35 |
+
"django": false
|
| 36 |
+
}
|
| 37 |
+
}
|
testbed/django__django/.git-blame-ignore-revs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ca88caa1031c0de545d82de8d90dcae0e03651fb
|
| 2 |
+
c5cd8783825b5f6384417dac5f3889b4210b7d08
|
| 3 |
+
9c19aff7c7561e3a82978a272ecdaad40dda5c00
|
| 4 |
+
7119f40c9881666b6f9b5cf7df09ee1d21cc8344
|
| 5 |
+
c18861804feb6a97afbeabb51be748dd60a04458
|
| 6 |
+
097e3a70c1481ee7b042b2edd91b2be86fb7b5b6
|
| 7 |
+
534ac4829764f317cf2fbc4a18354fcc998c1425
|
| 8 |
+
ba755ca13123d2691a0926ddb64e5d0a2906a880
|
| 9 |
+
14459f80ee3a9e005989db37c26fd13bb6d2fab2
|
testbed/django__django/.gitattributes
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Normalize line endings to avoid spurious failures in the core test suite on Windows.
|
| 2 |
+
*html text eol=lf
|
| 3 |
+
*css text eol=lf
|
| 4 |
+
*js text eol=lf
|
| 5 |
+
tests/staticfiles_tests/apps/test/static/test/*txt text eol=lf
|
| 6 |
+
tests/staticfiles_tests/project/documents/test/*txt text eol=lf
|
| 7 |
+
docs/releases/*.txt merge=union
|
testbed/django__django/.gitignore
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# If you need to exclude files such as those generated by an IDE, use
|
| 2 |
+
# $GIT_DIR/info/exclude or the core.excludesFile configuration variable as
|
| 3 |
+
# described in https://git-scm.com/docs/gitignore
|
| 4 |
+
|
| 5 |
+
*.egg-info
|
| 6 |
+
*.pot
|
| 7 |
+
*.py[co]
|
| 8 |
+
.tox/
|
| 9 |
+
__pycache__
|
| 10 |
+
MANIFEST
|
| 11 |
+
dist/
|
| 12 |
+
docs/_build/
|
| 13 |
+
docs/locale/
|
| 14 |
+
node_modules/
|
| 15 |
+
tests/coverage_html/
|
| 16 |
+
tests/.coverage*
|
| 17 |
+
build/
|
| 18 |
+
tests/report/
|
testbed/django__django/.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
repos:
|
| 2 |
+
- repo: https://github.com/psf/black
|
| 3 |
+
rev: 23.7.0
|
| 4 |
+
hooks:
|
| 5 |
+
- id: black
|
| 6 |
+
exclude: \.py-tpl$
|
| 7 |
+
- repo: https://github.com/adamchainz/blacken-docs
|
| 8 |
+
rev: 1.13.0
|
| 9 |
+
hooks:
|
| 10 |
+
- id: blacken-docs
|
| 11 |
+
additional_dependencies:
|
| 12 |
+
- black==23.7.0
|
| 13 |
+
- repo: https://github.com/PyCQA/isort
|
| 14 |
+
rev: 5.12.0
|
| 15 |
+
hooks:
|
| 16 |
+
- id: isort
|
| 17 |
+
- repo: https://github.com/PyCQA/flake8
|
| 18 |
+
rev: 6.0.0
|
| 19 |
+
hooks:
|
| 20 |
+
- id: flake8
|
| 21 |
+
- repo: https://github.com/pre-commit/mirrors-eslint
|
| 22 |
+
rev: v8.44.0
|
| 23 |
+
hooks:
|
| 24 |
+
- id: eslint
|
testbed/django__django/.readthedocs.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Configuration for the Read The Docs (RTD) builds of the documentation.
|
| 2 |
+
# Ref: https://docs.readthedocs.io/en/stable/config-file/v2.html
|
| 3 |
+
# The python.install.requirements pins the version of Sphinx used.
|
| 4 |
+
version: 2
|
| 5 |
+
|
| 6 |
+
build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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Django was originally created in late 2003 at World Online, the web division
|
| 2 |
+
of the Lawrence Journal-World newspaper in Lawrence, Kansas.
|
| 3 |
+
|
| 4 |
+
Here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS --
|
| 5 |
+
people who have submitted patches, reported bugs, added translations, helped
|
| 6 |
+
answer newbie questions, and generally made Django that much better:
|
| 7 |
+
|
| 8 |
+
Aaron Cannon <cannona@fireantproductions.com>
|
| 9 |
+
Aaron Swartz <http://www.aaronsw.com/>
|
| 10 |
+
Aaron T. Myers <atmyers@gmail.com>
|
| 11 |
+
Abeer Upadhyay <ab.esquarer@gmail.com>
|
| 12 |
+
Abhijeet Viswa <abhijeetviswa@gmail.com>
|
| 13 |
+
Abhinav Patil <https://github.com/ubadub/>
|
| 14 |
+
Abhinav Yadav <abhinav.sny.2002+django@gmail.com>
|
| 15 |
+
Abhishek Gautam <abhishekg1128@yahoo.com>
|
| 16 |
+
Abhyudai <https://github.com/abhiabhi94>
|
| 17 |
+
Adam Allred <adam.w.allred@gmail.com>
|
| 18 |
+
Adam Bogdał <adam@bogdal.pl>
|
| 19 |
+
Adam Donaghy
|
| 20 |
+
Adam Johnson <https://github.com/adamchainz>
|
| 21 |
+
Adam Malinowski <https://adammalinowski.co.uk/>
|
| 22 |
+
Adam Vandenberg
|
| 23 |
+
Ade Lee <alee@redhat.com>
|
| 24 |
+
Adiyat Mubarak <adiyatmubarak@gmail.com>
|
| 25 |
+
Adnan Umer <u.adnan@outlook.com>
|
| 26 |
+
Arslan Noor <arslannoorpansota@gmail.com>
|
| 27 |
+
Adrian Holovaty <adrian@holovaty.com>
|
| 28 |
+
Adrian Torres <atorresj@redhat.com>
|
| 29 |
+
Adrien Lemaire <lemaire.adrien@gmail.com>
|
| 30 |
+
Afonso Fernández Nogueira <fonzzo.django@gmail.com>
|
| 31 |
+
AgarFu <heaven@croasanaso.sytes.net>
|
| 32 |
+
Ahmad Alhashemi <trans@ahmadh.com>
|
| 33 |
+
Ahmad Al-Ibrahim
|
| 34 |
+
Ahmed Eltawela <https://github.com/ahmedabt>
|
| 35 |
+
ajs <adi@sieker.info>
|
| 36 |
+
Akash Agrawal <akashrocksha@gmail.com>
|
| 37 |
+
Akash Kumar Sen <akashkumarsen4@gmail.com>
|
| 38 |
+
Akis Kesoglou <akiskesoglou@gmail.com>
|
| 39 |
+
Aksel Ethem <aksel.ethem@gmail.com>
|
| 40 |
+
Akshesh Doshi <aksheshdoshi+django@gmail.com>
|
| 41 |
+
alang@bright-green.com
|
| 42 |
+
Alasdair Nicol <https://al.sdair.co.uk/>
|
| 43 |
+
Albert Wang <https://github.com/albertyw/>
|
| 44 |
+
Alcides Fonseca
|
| 45 |
+
Aldian Fazrihady <mobile@aldian.net>
|
| 46 |
+
Aleksandra Sendecka <asendecka@hauru.eu>
|
| 47 |
+
Aleksi Häkli <aleksi.hakli@iki.fi>
|
| 48 |
+
Alex Dutton <django@alexdutton.co.uk>
|
| 49 |
+
Alexander Myodov <alex@myodov.com>
|
| 50 |
+
Alexandr Tatarinov <tatarinov.dev@gmail.com>
|
| 51 |
+
Alex Aktsipetrov <alex.akts@gmail.com>
|
| 52 |
+
Alex Becker <https://alexcbecker.net/>
|
| 53 |
+
Alex Couper <http://alexcouper.com/>
|
| 54 |
+
Alex Dedul
|
| 55 |
+
Alex Gaynor <alex.gaynor@gmail.com>
|
| 56 |
+
Alex Hill <alex@hill.net.au>
|
| 57 |
+
Alex Ogier <alex.ogier@gmail.com>
|
| 58 |
+
Alex Robbins <alexander.j.robbins@gmail.com>
|
| 59 |
+
Alexey Boriskin <alex@boriskin.me>
|
| 60 |
+
Alexey Tsivunin <most-208@yandex.ru>
|
| 61 |
+
Ali Vakilzade <ali@vakilzade.com>
|
| 62 |
+
Aljaž Košir <aljazkosir5@gmail.com>
|
| 63 |
+
Aljosa Mohorovic <aljosa.mohorovic@gmail.com>
|
| 64 |
+
Alokik Vijay <alokik.roe@gmail.com>
|
| 65 |
+
Amit Chakradeo <https://amit.chakradeo.net/>
|
| 66 |
+
Amit Ramon <amit.ramon@gmail.com>
|
| 67 |
+
Amit Upadhyay <http://www.amitu.com/blog/>
|
| 68 |
+
A. Murat Eren <meren@pardus.org.tr>
|
| 69 |
+
Ana Belen Sarabia <belensarabia@gmail.com>
|
| 70 |
+
Ana Krivokapic <https://github.com/infraredgirl>
|
| 71 |
+
Andi Albrecht <albrecht.andi@gmail.com>
|
| 72 |
+
André Ericson <de.ericson@gmail.com>
|
| 73 |
+
Andrei Kulakov <andrei.avk@gmail.com>
|
| 74 |
+
Andreas
|
| 75 |
+
Andreas Mock <andreas.mock@web.de>
|
| 76 |
+
Andreas Pelme <andreas@pelme.se>
|
| 77 |
+
Andrés Torres Marroquín <andres.torres.marroquin@gmail.com>
|
| 78 |
+
Andrew Brehaut <https://brehaut.net/blog>
|
| 79 |
+
Andrew Clark <amclark7@gmail.com>
|
| 80 |
+
Andrew Durdin <adurdin@gmail.com>
|
| 81 |
+
Andrew Godwin <andrew@aeracode.org>
|
| 82 |
+
Andrew Pinkham <http://AndrewsForge.com>
|
| 83 |
+
Andrews Medina <andrewsmedina@gmail.com>
|
| 84 |
+
Andrew Northall <andrew@northall.me.uk>
|
| 85 |
+
Andriy Sokolovskiy <me@asokolovskiy.com>
|
| 86 |
+
Andy Chosak <andy@chosak.org>
|
| 87 |
+
Andy Dustman <farcepest@gmail.com>
|
| 88 |
+
Andy Gayton <andy-django@thecablelounge.com>
|
| 89 |
+
andy@jadedplanet.net
|
| 90 |
+
Anssi Kääriäinen <akaariai@gmail.com>
|
| 91 |
+
ant9000@netwise.it
|
| 92 |
+
Anthony Briggs <anthony.briggs@gmail.com>
|
| 93 |
+
Anthony Wright <ryow.college@gmail.com>
|
| 94 |
+
Anton Samarchyan <desecho@gmail.com>
|
| 95 |
+
Antoni Aloy
|
| 96 |
+
Antonio Cavedoni <http://cavedoni.com/>
|
| 97 |
+
Antonis Christofides <anthony@itia.ntua.gr>
|
| 98 |
+
Antti Haapala <antti@industrialwebandmagic.com>
|
| 99 |
+
Antti Kaihola <http://djangopeople.net/akaihola/>
|
| 100 |
+
Anubhav Joshi <anubhav9042@gmail.com>
|
| 101 |
+
Anvesh Mishra <anveshgreat11@gmail.com>
|
| 102 |
+
Aram Dulyan
|
| 103 |
+
arien <regexbot@gmail.com>
|
| 104 |
+
Armin Ronacher
|
| 105 |
+
Aron Podrigal <aronp@guaranteedplus.com>
|
| 106 |
+
Arsalan Ghassemi <arsalan.ghassemi@gmail.com>
|
| 107 |
+
Artem Gnilov <boobsd@gmail.com>
|
| 108 |
+
Arthur <avandorp@gmail.com>
|
| 109 |
+
Arthur Jovart <arthur@jovart.com>
|
| 110 |
+
Arthur Koziel <http://arthurkoziel.com>
|
| 111 |
+
Arthur Moreira <moreirarthur96@gmail.com>
|
| 112 |
+
Arthur Rio <arthur.rio44@gmail.com>
|
| 113 |
+
Arvis Bickovskis <viestards.lists@gmail.com>
|
| 114 |
+
Arya Khaligh <bartararya@gmail.com>
|
| 115 |
+
Aryeh Leib Taurog <http://www.aryehleib.com/>
|
| 116 |
+
A S Alam <aalam@users.sf.net>
|
| 117 |
+
Asif Saif Uddin <auvipy@gmail.com>
|
| 118 |
+
atlithorn <atlithorn@gmail.com>
|
| 119 |
+
Audrey Roy <http://audreymroy.com/>
|
| 120 |
+
av0000@mail.ru
|
| 121 |
+
Axel Haustant <noirbizarre@gmail.com>
|
| 122 |
+
Aymeric Augustin <aymeric.augustin@m4x.org>
|
| 123 |
+
Bahadır Kandemir <bahadir@pardus.org.tr>
|
| 124 |
+
Baishampayan Ghose
|
| 125 |
+
Baptiste Mispelon <bmispelon@gmail.com>
|
| 126 |
+
Barry Pederson <bp@barryp.org>
|
| 127 |
+
Bartolome Sanchez Salado <i42sasab@uco.es>
|
| 128 |
+
Barton Ip <notbartonip@gmail.com>
|
| 129 |
+
Bartosz Grabski <bartosz.grabski@gmail.com>
|
| 130 |
+
Bashar Al-Abdulhadi
|
| 131 |
+
Bastian Kleineidam <calvin@debian.org>
|
| 132 |
+
Batiste Bieler <batiste.bieler@gmail.com>
|
| 133 |
+
Batman
|
| 134 |
+
Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
|
| 135 |
+
Baurzhan Ismagulov <ibr@radix50.net>
|
| 136 |
+
Ben Dean Kawamura <ben.dean.kawamura@gmail.com>
|
| 137 |
+
Ben Firshman <ben@firshman.co.uk>
|
| 138 |
+
Ben Godfrey <http://aftnn.org>
|
| 139 |
+
Benjamin Wohlwend <piquadrat@gmail.com>
|
| 140 |
+
Ben Khoo <khoobks@westnet.com.au>
|
| 141 |
+
Ben Lomax <lomax.on.the.run@gmail.com>
|
| 142 |
+
Ben Slavin <benjamin.slavin@gmail.com>
|
| 143 |
+
Ben Sturmfels <ben@sturm.com.au>
|
| 144 |
+
Berker Peksag <berker.peksag@gmail.com>
|
| 145 |
+
Bernd Schlapsi
|
| 146 |
+
Bernhard Essl <me@bernhardessl.com>
|
| 147 |
+
berto
|
| 148 |
+
Bhuvnesh Sharma <bhuvnesh875@gmail.com>
|
| 149 |
+
Bill Fenner <fenner@gmail.com>
|
| 150 |
+
Bjørn Stabell <bjorn@exoweb.net>
|
| 151 |
+
Bo Marchman <bo.marchman@gmail.com>
|
| 152 |
+
Bogdan Mateescu
|
| 153 |
+
Bojan Mihelac <bmihelac@mihelac.org>
|
| 154 |
+
Bouke Haarsma <bouke@haarsma.eu>
|
| 155 |
+
Božidar Benko <bbenko@gmail.com>
|
| 156 |
+
Brad Melin <melinbrad@gmail.com>
|
| 157 |
+
Brandon Chinn <https://brandonchinn178.github.io/>
|
| 158 |
+
Brant Harris
|
| 159 |
+
Brendan Hayward <brendanhayward85@gmail.com>
|
| 160 |
+
Brendan Quinn <brendan@cluefulmedia.com>
|
| 161 |
+
Brenton Simpson <http://theillustratedlife.com>
|
| 162 |
+
Brett Cannon <brett@python.org>
|
| 163 |
+
Brett Hoerner <bretthoerner@bretthoerner.com>
|
| 164 |
+
Brian Beck <http://blog.brianbeck.com/>
|
| 165 |
+
Brian Fabian Crain <http://www.bfc.do/>
|
| 166 |
+
Brian Harring <ferringb@gmail.com>
|
| 167 |
+
Brian Helba <brian.helba@kitware.com>
|
| 168 |
+
Brian Ray <http://brianray.chipy.org/>
|
| 169 |
+
Brian Rosner <brosner@gmail.com>
|
| 170 |
+
Bruce Kroeze <https://coderseye.com/>
|
| 171 |
+
Bruno Alla <alla.brunoo@gmail.com>
|
| 172 |
+
Bruno Renié <buburno@gmail.com>
|
| 173 |
+
brut.alll@gmail.com
|
| 174 |
+
Bryan Chow <bryan at verdjn dot com>
|
| 175 |
+
Bryan Veloso <bryan@revyver.com>
|
| 176 |
+
bthomas
|
| 177 |
+
btoll@bestweb.net
|
| 178 |
+
C8E
|
| 179 |
+
Caio Ariede <caio.ariede@gmail.com>
|
| 180 |
+
Calvin Spealman <ironfroggy@gmail.com>
|
| 181 |
+
Cameron Curry
|
| 182 |
+
Cameron Knight (ckknight)
|
| 183 |
+
Can Burak Çilingir <canburak@cs.bilgi.edu.tr>
|
| 184 |
+
Can Sarıgöl <ertugrulsarigol@gmail.com>
|
| 185 |
+
Carl Meyer <carl@oddbird.net>
|
| 186 |
+
Carles Pina i Estany <carles@pina.cat>
|
| 187 |
+
Carlos Eduardo de Paula <carlosedp@gmail.com>
|
| 188 |
+
Carlos Matías de la Torre <cmdelatorre@gmail.com>
|
| 189 |
+
Carlton Gibson <carlton.gibson@noumenal.es>
|
| 190 |
+
cedric@terramater.net
|
| 191 |
+
Chad Whitman <chad.whitman@icloud.com>
|
| 192 |
+
ChaosKCW
|
| 193 |
+
Charlie Leifer <coleifer@gmail.com>
|
| 194 |
+
charly.wilhelm@gmail.com
|
| 195 |
+
Chason Chaffin <chason@gmail.com>
|
| 196 |
+
Cheng Zhang
|
| 197 |
+
Chris Adams
|
| 198 |
+
Chris Beaven <smileychris@gmail.com>
|
| 199 |
+
Chris Bennett <chrisrbennett@yahoo.com>
|
| 200 |
+
Chris Cahoon <chris.cahoon@gmail.com>
|
| 201 |
+
Chris Chamberlin <dja@cdc.msbx.net>
|
| 202 |
+
Chris Jerdonek
|
| 203 |
+
Chris Jones <chris@brack3t.com>
|
| 204 |
+
Chris Lamb <chris@chris-lamb.co.uk>
|
| 205 |
+
Chris Streeter <chris@chrisstreeter.com>
|
| 206 |
+
Christian Barcenas <christian@cbarcenas.com>
|
| 207 |
+
Christian Metts
|
| 208 |
+
Christian Oudard <christian.oudard@gmail.com>
|
| 209 |
+
Christian Tanzer <tanzer@swing.co.at>
|
| 210 |
+
Christoffer Sjöbergsson
|
| 211 |
+
Christophe Pettus <xof@thebuild.com>
|
| 212 |
+
Christopher Adams <http://christopheradams.info>
|
| 213 |
+
Christopher Babiak <chrisbabiak@gmail.com>
|
| 214 |
+
Christopher Lenz <https://www.cmlenz.net/>
|
| 215 |
+
Christoph Mędrela <chris.medrela@gmail.com>
|
| 216 |
+
Chris Wagner <cw264701@ohio.edu>
|
| 217 |
+
Chris Wesseling <Chris.Wesseling@cwi.nl>
|
| 218 |
+
Chris Wilson <chris+github@qwirx.com>
|
| 219 |
+
Ciaran McCormick <ciaran@ciaranmccormick.com>
|
| 220 |
+
Claude Paroz <claude@2xlibre.net>
|
| 221 |
+
Clint Ecker
|
| 222 |
+
colin@owlfish.com
|
| 223 |
+
Colin Wood <cwood06@gmail.com>
|
| 224 |
+
Collin Anderson <cmawebsite@gmail.com>
|
| 225 |
+
Collin Grady <collin@collingrady.com>
|
| 226 |
+
Colton Hicks <coltonbhicks@gmail.com>
|
| 227 |
+
Craig Blaszczyk <masterjakul@gmail.com>
|
| 228 |
+
crankycoder@gmail.com
|
| 229 |
+
Curtis Maloney (FunkyBob) <curtis@tinbrain.net>
|
| 230 |
+
dackze+django@gmail.com
|
| 231 |
+
Dagur Páll Ammendrup <dagurp@gmail.com>
|
| 232 |
+
Dane Springmeyer
|
| 233 |
+
Dan Fairs <dan@fezconsulting.com>
|
| 234 |
+
Daniel Alves Barbosa de Oliveira Vaz <danielvaz@gmail.com>
|
| 235 |
+
Daniel Duan <DaNmarner@gmail.com>
|
| 236 |
+
Daniele Procida <daniele@vurt.org>
|
| 237 |
+
Daniel Fairhead <danthedeckie@gmail.com>
|
| 238 |
+
Daniel Greenfeld
|
| 239 |
+
dAniel hAhler
|
| 240 |
+
Daniel Jilg <daniel@breakthesystem.org>
|
| 241 |
+
Daniel Lindsley <daniel@toastdriven.com>
|
| 242 |
+
Daniel Poelzleithner <https://poelzi.org/>
|
| 243 |
+
Daniel Pyrathon <pirosb3@gmail.com>
|
| 244 |
+
Daniel Roseman <http://roseman.org.uk/>
|
| 245 |
+
Daniel Tao <https://philosopherdeveloper.com/>
|
| 246 |
+
Daniel Wiesmann <daniel.wiesmann@gmail.com>
|
| 247 |
+
Danilo Bargen
|
| 248 |
+
Dan Johnson <danj.py@gmail.com>
|
| 249 |
+
Dan Palmer <dan@danpalmer.me>
|
| 250 |
+
Dan Poirier <poirier@pobox.com>
|
| 251 |
+
Dan Stephenson <http://dan.io/>
|
| 252 |
+
Dan Watson <http://danwatson.net/>
|
| 253 |
+
dave@thebarproject.com
|
| 254 |
+
David Ascher <https://ascher.ca/>
|
| 255 |
+
David Avsajanishvili <avsd05@gmail.com>
|
| 256 |
+
David Blewett <david@dawninglight.net>
|
| 257 |
+
David Brenneman <http://davidbrenneman.com>
|
| 258 |
+
David Cramer <dcramer@gmail.com>
|
| 259 |
+
David Danier <david.danier@team23.de>
|
| 260 |
+
David Eklund
|
| 261 |
+
David Foster <david@dafoster.net>
|
| 262 |
+
David Gouldin <dgouldin@gmail.com>
|
| 263 |
+
david@kazserve.org
|
| 264 |
+
David Krauth
|
| 265 |
+
David Larlet <https://larlet.fr/david/>
|
| 266 |
+
David Reynolds <david@reynoldsfamily.org.uk>
|
| 267 |
+
David Sanders <dsanders11@ucsbalum.com>
|
| 268 |
+
David Schein
|
| 269 |
+
David Tulig <david.tulig@gmail.com>
|
| 270 |
+
David Winterbottom <david.winterbottom@gmail.com>
|
| 271 |
+
David Wobrock <david.wobrock@gmail.com>
|
| 272 |
+
Davide Ceretti <dav.ceretti@gmail.com>
|
| 273 |
+
Deep L. Sukhwani <deepsukhwani@gmail.com>
|
| 274 |
+
Deepak Thukral <deep.thukral@gmail.com>
|
| 275 |
+
Denis Kuzmichyov <kuzmichyov@gmail.com>
|
| 276 |
+
Dennis Schwertel <dennisschwertel@gmail.com>
|
| 277 |
+
Derek Willis <http://blog.thescoop.org/>
|
| 278 |
+
Deric Crago <deric.crago@gmail.com>
|
| 279 |
+
deric@monowerks.com
|
| 280 |
+
Deryck Hodge <http://www.devurandom.org/>
|
| 281 |
+
Dimitris Glezos <dimitris@glezos.com>
|
| 282 |
+
Dirk Datzert <dummy@habmalnefrage.de>
|
| 283 |
+
Dirk Eschler <dirk.eschler@gmx.net>
|
| 284 |
+
Dmitri Fedortchenko <zeraien@gmail.com>
|
| 285 |
+
Dmitry Jemerov <intelliyole@gmail.com>
|
| 286 |
+
dne@mayonnaise.net
|
| 287 |
+
Dolan Antenucci <antenucci.d@gmail.com>
|
| 288 |
+
Donald Harvey <donald@donaldharvey.co.uk>
|
| 289 |
+
Donald Stufft <donald@stufft.io>
|
| 290 |
+
Don Spaulding <donspauldingii@gmail.com>
|
| 291 |
+
Doug Beck <doug@douglasbeck.com>
|
| 292 |
+
Doug Napoleone <doug@dougma.com>
|
| 293 |
+
dready <wil@mojipage.com>
|
| 294 |
+
Durval Carvalho de Souza <dudurval2@gmail.com>
|
| 295 |
+
dusk@woofle.net
|
| 296 |
+
Dustyn Gibson <miigotu@gmail.com>
|
| 297 |
+
Ed Morley <https://github.com/edmorley>
|
| 298 |
+
Egidijus Macijauskas <e.macijauskas@outlook.com>
|
| 299 |
+
eibaan@gmail.com
|
| 300 |
+
elky <http://elky.me/>
|
| 301 |
+
Emmanuelle Delescolle <https://github.com/nanuxbe>
|
| 302 |
+
Emil Stenström <em@kth.se>
|
| 303 |
+
enlight
|
| 304 |
+
Enrico <rico.bl@gmail.com>
|
| 305 |
+
Eric Boersma <eric.boersma@gmail.com>
|
| 306 |
+
Eric Brandwein <brandweineric@gmail.com>
|
| 307 |
+
Eric Floehr <eric@intellovations.com>
|
| 308 |
+
Eric Florenzano <floguy@gmail.com>
|
| 309 |
+
Eric Holscher <http://ericholscher.com>
|
| 310 |
+
Eric Moritz <http://eric.themoritzfamily.com/>
|
| 311 |
+
Eric Palakovich Carr <carreric@gmail.com>
|
| 312 |
+
Erik Karulf <erik@karulf.com>
|
| 313 |
+
Erik Romijn <django@solidlinks.nl>
|
| 314 |
+
eriks@win.tue.nl
|
| 315 |
+
Erwin Junge <erwin@junge.nl>
|
| 316 |
+
Esdras Beleza <linux@esdrasbeleza.com>
|
| 317 |
+
Espen Grindhaug <http://grindhaug.org/>
|
| 318 |
+
Étienne Beaulé <beauleetienne0@gmail.com>
|
| 319 |
+
Eugene Lazutkin <http://lazutkin.com/blog/>
|
| 320 |
+
Evan Grim <https://github.com/egrim>
|
| 321 |
+
Fabian Büchler <fabian.buechler@inoqo.com>
|
| 322 |
+
Fabrice Aneche <akh@nobugware.com>
|
| 323 |
+
Farhaan Bukhsh <farhaan.bukhsh@gmail.com>
|
| 324 |
+
favo@exoweb.net
|
| 325 |
+
fdr <drfarina@gmail.com>
|
| 326 |
+
Federico Capoano <nemesis@ninux.org>
|
| 327 |
+
Felipe Lee <felipe.lee.garcia@gmail.com>
|
| 328 |
+
Filip Noetzel <http://filip.noetzel.co.uk/>
|
| 329 |
+
Filip Wasilewski <filip.wasilewski@gmail.com>
|
| 330 |
+
Finn Gruwier Larsen <finn@gruwier.dk>
|
| 331 |
+
Fiza Ashraf <fizaashraf37@gmail.com>
|
| 332 |
+
Flávio Juvenal da Silva Junior <flavio@vinta.com.br>
|
| 333 |
+
flavio.curella@gmail.com
|
| 334 |
+
Florian Apolloner <florian@apolloner.eu>
|
| 335 |
+
Florian Demmer <fdemmer@gmail.com>
|
| 336 |
+
Florian Moussous <florian.moussous@gmail.com>
|
| 337 |
+
fnaimi66 <https://github.com/fnaimi66>
|
| 338 |
+
Fran Hrženjak <fran.hrzenjak@gmail.com>
|
| 339 |
+
Francesco Panico <panico.francesco@gmail.com>
|
| 340 |
+
Francisco Albarran Cristobal <pahko.xd@gmail.com>
|
| 341 |
+
Francisco Couzo <franciscouzo@gmail.com>
|
| 342 |
+
François Freitag <mail@franek.fr>
|
| 343 |
+
Frank Tegtmeyer <fte@fte.to>
|
| 344 |
+
Frank Wierzbicki
|
| 345 |
+
Frank Wiles <frank@revsys.com>
|
| 346 |
+
František Malina <https://unilexicon.com/fm/>
|
| 347 |
+
Fraser Nevett <mail@nevett.org>
|
| 348 |
+
Gabriel Grant <g@briel.ca>
|
| 349 |
+
Gabriel Hurley <gabriel@strikeawe.com>
|
| 350 |
+
gandalf@owca.info
|
| 351 |
+
Garry Lawrence
|
| 352 |
+
Garry Polley <garrympolley@gmail.com>
|
| 353 |
+
Garth Kidd <http://www.deadlybloodyserious.com/>
|
| 354 |
+
Gary Wilson <gary.wilson@gmail.com>
|
| 355 |
+
Gasper Koren
|
| 356 |
+
Gasper Zejn <zejn@kiberpipa.org>
|
| 357 |
+
Gav O'Connor <https://github.com/Scalamoosh>
|
| 358 |
+
Gavin Wahl <gavinwahl@gmail.com>
|
| 359 |
+
Ge Hanbin <xiaomiba0904@gmail.com>
|
| 360 |
+
geber@datacollect.com
|
| 361 |
+
Geert Vanderkelen
|
| 362 |
+
George Karpenkov <george@metaworld.ru>
|
| 363 |
+
George Song <george@damacy.net>
|
| 364 |
+
George Vilches <gav@thataddress.com>
|
| 365 |
+
Georg "Hugo" Bauer <gb@hugo.westfalen.de>
|
| 366 |
+
Georgi Stanojevski <glisha@gmail.com>
|
| 367 |
+
Gerardo Orozco <gerardo.orozco.mosqueda@gmail.com>
|
| 368 |
+
Gil Gonçalves <lursty@gmail.com>
|
| 369 |
+
Girish Kumar <girishkumarkh@gmail.com>
|
| 370 |
+
Girish Sontakke <girishsontakke7@gmail.com>
|
| 371 |
+
Gisle Aas <gisle@aas.no>
|
| 372 |
+
Glenn Maynard <glenn@zewt.org>
|
| 373 |
+
glin@seznam.cz
|
| 374 |
+
GomoX <gomo@datafull.com>
|
| 375 |
+
Gonzalo Saavedra <gonzalosaavedra@gmail.com>
|
| 376 |
+
Gopal Narayanan <gopastro@gmail.com>
|
| 377 |
+
Graham Carlyle <graham.carlyle@maplecroft.net>
|
| 378 |
+
Grant Jenks <contact@grantjenks.com>
|
| 379 |
+
Greg Chapple <gregchapple1@gmail.com>
|
| 380 |
+
Greg Twohig
|
| 381 |
+
Gregor Allensworth <greg.allensworth@gmail.com>
|
| 382 |
+
Gregor Müllegger <gregor@muellegger.de>
|
| 383 |
+
Grigory Fateyev <greg@dial.com.ru>
|
| 384 |
+
Grzegorz Ślusarek <grzegorz.slusarek@gmail.com>
|
| 385 |
+
Guilherme Mesquita Gondim <semente@taurinus.org>
|
| 386 |
+
Guillaume Pannatier <guillaume.pannatier@gmail.com>
|
| 387 |
+
Gustavo Picon
|
| 388 |
+
hambaloney
|
| 389 |
+
Hang Park <hangpark@kaist.ac.kr>
|
| 390 |
+
Hannes Ljungberg <hannes.ljungberg@gmail.com>
|
| 391 |
+
Hannes Struß <x@hannesstruss.de>
|
| 392 |
+
Harm Geerts <hgeerts@gmail.com>
|
| 393 |
+
Hasan Ramezani <hasan.r67@gmail.com>
|
| 394 |
+
Hawkeye
|
| 395 |
+
Helen Sherwood-Taylor <helen@rrdlabs.co.uk>
|
| 396 |
+
Henrique Romano <onaiort@gmail.com>
|
| 397 |
+
Henry Dang <henrydangprg@gmail.com>
|
| 398 |
+
Hidde Bultsma
|
| 399 |
+
Himanshu Chauhan <hchauhan1404@outlook.com>
|
| 400 |
+
hipertracker@gmail.com
|
| 401 |
+
Hiroki Kiyohara <hirokiky@gmail.com>
|
| 402 |
+
Honza Král <honza.kral@gmail.com>
|
| 403 |
+
Horst Gutmann <zerok@zerokspot.com>
|
| 404 |
+
Hugo Osvaldo Barrera <hugo@barrera.io>
|
| 405 |
+
HyukJin Jang <wkdgurwls00@naver.com>
|
| 406 |
+
Hyun Mi Ae
|
| 407 |
+
Iacopo Spalletti <i.spalletti@nephila.it>
|
| 408 |
+
Ian A Wilson <http://ianawilson.com>
|
| 409 |
+
Ian Clelland <clelland@gmail.com>
|
| 410 |
+
Ian G. Kelly <ian.g.kelly@gmail.com>
|
| 411 |
+
Ian Holsman <http://feh.holsman.net/>
|
| 412 |
+
Ian Lee <IanLee1521@gmail.com>
|
| 413 |
+
Ibon <ibonso@gmail.com>
|
| 414 |
+
Idan Gazit <idan@gazit.me>
|
| 415 |
+
Idan Melamed
|
| 416 |
+
Ifedapo Olarewaju <ifedapoolarewaju@gmail.com>
|
| 417 |
+
Igor Kolar <ike@email.si>
|
| 418 |
+
Illia Volochii <illia.volochii@gmail.com>
|
| 419 |
+
Ilya Bass
|
| 420 |
+
Ilya Semenov <semenov@inetss.com>
|
| 421 |
+
Ingo Klöcker <djangoproject@ingo-kloecker.de>
|
| 422 |
+
I.S. van Oostveen <v.oostveen@idca.nl>
|
| 423 |
+
Iuri de Silvio <https://github.com/iurisilvio>
|
| 424 |
+
ivan.chelubeev@gmail.com
|
| 425 |
+
Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
|
| 426 |
+
Jaap Roes <jaap.roes@gmail.com>
|
| 427 |
+
Jack Moffitt <https://metajack.im/>
|
| 428 |
+
Jacob Burch <jacobburch@gmail.com>
|
| 429 |
+
Jacob Green
|
| 430 |
+
Jacob Kaplan-Moss <jacob@jacobian.org>
|
| 431 |
+
Jacob Rief <jacob.rief@gmail.com>
|
| 432 |
+
Jacob Walls <http://www.jacobtylerwalls.com/>
|
| 433 |
+
Jakub Paczkowski <jakub@paczkowski.eu>
|
| 434 |
+
Jakub Wilk <jwilk@jwilk.net>
|
| 435 |
+
Jakub Wiśniowski <restless.being@gmail.com>
|
| 436 |
+
james_027@yahoo.com
|
| 437 |
+
James Aylett
|
| 438 |
+
James Bennett <james@b-list.org>
|
| 439 |
+
James Gillard <jamesgillard@live.co.uk>
|
| 440 |
+
James Murty
|
| 441 |
+
James Tauber <jtauber@jtauber.com>
|
| 442 |
+
James Timmins <jameshtimmins@gmail.com>
|
| 443 |
+
James Turk <dev@jamesturk.net>
|
| 444 |
+
James Wheare <django@sparemint.com>
|
| 445 |
+
Jamie Matthews <jamie@mtth.org>
|
| 446 |
+
Jannis Leidel <jannis@leidel.info>
|
| 447 |
+
Janos Guljas
|
| 448 |
+
Jan Pazdziora
|
| 449 |
+
Jan Rademaker
|
| 450 |
+
Jarek Głowacki <jarekwg@gmail.com>
|
| 451 |
+
Jarek Zgoda <jarek.zgoda@gmail.com>
|
| 452 |
+
Jarosław Wygoda <jaroslaw@wygoda.me>
|
| 453 |
+
Jason Davies (Esaj) <https://www.jasondavies.com/>
|
| 454 |
+
Jason Huggins <http://www.jrandolph.com/blog/>
|
| 455 |
+
Jason McBrayer <http://www.carcosa.net/jason/>
|
| 456 |
+
jason.sidabras@gmail.com
|
| 457 |
+
Jason Yan <tailofthesun@gmail.com>
|
| 458 |
+
Javier Mansilla <javimansilla@gmail.com>
|
| 459 |
+
Jay Parlar <parlar@gmail.com>
|
| 460 |
+
Jay Welborn <jesse.welborn@gmail.com>
|
| 461 |
+
Jay Wineinger <jay.wineinger@gmail.com>
|
| 462 |
+
J. Clifford Dyer <jcd@sdf.lonestar.org>
|
| 463 |
+
jcrasta@gmail.com
|
| 464 |
+
jdetaeye
|
| 465 |
+
Jeff Anderson <jefferya@programmerq.net>
|
| 466 |
+
Jeff Balogh <jbalogh@mozilla.com>
|
| 467 |
+
Jeff Hui <jeffkhui@gmail.com>
|
| 468 |
+
Jeffrey Gelens <jeffrey@gelens.org>
|
| 469 |
+
Jeff Triplett <jeff.triplett@gmail.com>
|
| 470 |
+
Jeffrey Yancey <jeffrey.yancey@gmail.com>
|
| 471 |
+
Jens Diemer <django@htfx.de>
|
| 472 |
+
Jens Page
|
| 473 |
+
Jensen Cochran <jensen.cochran@gmail.com>
|
| 474 |
+
Jeong-Min Lee <falsetru@gmail.com>
|
| 475 |
+
Jérémie Blaser <blaserje@gmail.com>
|
| 476 |
+
Jeremy Bowman <https://github.com/jmbowman>
|
| 477 |
+
Jeremy Carbaugh <jcarbaugh@gmail.com>
|
| 478 |
+
Jeremy Dunck <jdunck@gmail.com>
|
| 479 |
+
Jeremy Lainé <jeremy.laine@m4x.org>
|
| 480 |
+
Jerin Peter George <jerinpetergeorge@gmail.com>
|
| 481 |
+
Jesse Young <adunar@gmail.com>
|
| 482 |
+
Jezeniel Zapanta <jezeniel.zapanta@gmail.com>
|
| 483 |
+
jhenry <jhenry@theonion.com>
|
| 484 |
+
Jim Dalton <jim.dalton@gmail.com>
|
| 485 |
+
Jimmy Song <jaejoon@gmail.com>
|
| 486 |
+
Jiri Barton
|
| 487 |
+
Joachim Jablon <ewjoachim@gmail.com>
|
| 488 |
+
Joao Oliveira <joaoxsouls@gmail.com>
|
| 489 |
+
Joao Pedro Silva <j.pedro004@gmail.com>
|
| 490 |
+
Joe Heck <http://www.rhonabwy.com/wp/>
|
| 491 |
+
Joe Jackson <joe@joejackson.me>
|
| 492 |
+
Joel Bohman <mail@jbohman.com>
|
| 493 |
+
Joel Heenan <joelh-django@planetjoel.com>
|
| 494 |
+
Joel Watts <joel@joelwatts.com>
|
| 495 |
+
Joe Topjian <http://joe.terrarum.net/geek/code/python/django/>
|
| 496 |
+
Johan C. Stöver <johan@nilling.nl>
|
| 497 |
+
Johann Queuniet <johann.queuniet@adh.naellia.eu>
|
| 498 |
+
john@calixto.net
|
| 499 |
+
John D'Agostino <john.dagostino@gmail.com>
|
| 500 |
+
John D'Ambrosio <dambrosioj@gmail.com>
|
| 501 |
+
John Huddleston <huddlej@wwu.edu>
|
| 502 |
+
John Moses <moses.john.r@gmail.com>
|
| 503 |
+
John Paulett <john@paulett.org>
|
| 504 |
+
John Shaffer <jshaffer2112@gmail.com>
|
| 505 |
+
Jökull Sólberg Auðunsson <jokullsolberg@gmail.com>
|
| 506 |
+
Jon Dufresne <jon.dufresne@gmail.com>
|
| 507 |
+
Jon Janzen <jon@jonjanzen.com>
|
| 508 |
+
Jonas Haag <jonas@lophus.org>
|
| 509 |
+
Jonas Lundberg <jonas.lundberg@gmail.com>
|
| 510 |
+
Jonathan Davis <jonathandavis47780@gmail.com>
|
| 511 |
+
Jonatas C. D. <jonatas.cd@gmail.com>
|
| 512 |
+
Jonathan Buchanan <jonathan.buchanan@gmail.com>
|
| 513 |
+
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
|
| 514 |
+
Jonathan Feignberg <jdf@pobox.com>
|
| 515 |
+
Jonathan Slenders
|
| 516 |
+
Jonny Park <jonnythebard9@gmail.com>
|
| 517 |
+
Jordan Bae <qoentlr37@gmail.com>
|
| 518 |
+
Jordan Dimov <s3x3y1@gmail.com>
|
| 519 |
+
Jordi J. Tablada <jordi.joan@gmail.com>
|
| 520 |
+
Jorge Bastida <me@jorgebastida.com>
|
| 521 |
+
Jorge Gajon <gajon@gajon.org>
|
| 522 |
+
José Tomás Tocino García <josetomas.tocino@gmail.com>
|
| 523 |
+
Josef Rousek <josef.rousek@gmail.com>
|
| 524 |
+
Joseph Kocherhans <joseph@jkocherhans.com>
|
| 525 |
+
Josh Smeaton <josh.smeaton@gmail.com>
|
| 526 |
+
Joshua Cannon <joshdcannon@gmail.com>
|
| 527 |
+
Joshua Ginsberg <jag@flowtheory.net>
|
| 528 |
+
Jozko Skrablin <jozko.skrablin@gmail.com>
|
| 529 |
+
J. Pablo Fernandez <pupeno@pupeno.com>
|
| 530 |
+
jpellerin@gmail.com
|
| 531 |
+
Juan Catalano <catalanojuan@gmail.com>
|
| 532 |
+
Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com>
|
| 533 |
+
Juan Pedro Fisanotti <fisadev@gmail.com>
|
| 534 |
+
Julia Elman
|
| 535 |
+
Julia Matsieva <julia.matsieva@gmail.com>
|
| 536 |
+
Julian Bez
|
| 537 |
+
Julie Rymer <rymerjulie.pro@gmail.com>
|
| 538 |
+
Julien Phalip <jphalip@gmail.com>
|
| 539 |
+
Junyoung Choi <cupjoo@gmail.com>
|
| 540 |
+
junzhang.jn@gmail.com
|
| 541 |
+
Jure Cuhalev <gandalf@owca.info>
|
| 542 |
+
Justin Bronn <jbronn@gmail.com>
|
| 543 |
+
Justine Tunney <jtunney@gmail.com>
|
| 544 |
+
Justin Lilly <justinlilly@gmail.com>
|
| 545 |
+
Justin Michalicek <jmichalicek@gmail.com>
|
| 546 |
+
Justin Myles Holmes <justin@slashrootcafe.com>
|
| 547 |
+
Jyrki Pulliainen <jyrki.pulliainen@gmail.com>
|
| 548 |
+
Kacper Wolkiewicz <kac.wolkiewicz@gmail.com>
|
| 549 |
+
Kadesarin Sanjek
|
| 550 |
+
Kapil Bansal <kapilbansal.gbpecdelhi@gmail.com>
|
| 551 |
+
Karderio <karderio@gmail.com>
|
| 552 |
+
Karen Tracey <kmtracey@gmail.com>
|
| 553 |
+
Karol Sikora <elektrrrus@gmail.com>
|
| 554 |
+
Katherine “Kati” Michel <kthrnmichel@gmail.com>
|
| 555 |
+
Kathryn Killebrew <kathryn.killebrew@gmail.com>
|
| 556 |
+
Katie Miller <katie@sub50.com>
|
| 557 |
+
Keith Bussell <kbussell@gmail.com>
|
| 558 |
+
Kenneth Love <kennethlove@gmail.com>
|
| 559 |
+
Kent Hauser <kent@khauser.net>
|
| 560 |
+
Keryn Knight <keryn@kerynknight.com>
|
| 561 |
+
Kevin Grinberg <kevin@kevingrinberg.com>
|
| 562 |
+
Kevin Kubasik <kevin@kubasik.net>
|
| 563 |
+
Kevin McConnell <kevin.mcconnell@gmail.com>
|
| 564 |
+
Kieran Holland <http://www.kieranholland.com>
|
| 565 |
+
kilian <kilian.cavalotti@lip6.fr>
|
| 566 |
+
Kim Joon Hwan 김준환 <xncbf12@gmail.com>
|
| 567 |
+
Kim Soung Ryoul 김성렬 <kimsoungryoul@gmail.com>
|
| 568 |
+
Klaas van Schelven <klaas@vanschelven.com>
|
| 569 |
+
knox <christobzr@gmail.com>
|
| 570 |
+
konrad@gwu.edu
|
| 571 |
+
Kowito Charoenratchatabhan <kowito@felspar.com>
|
| 572 |
+
Krišjānis Vaiders <krisjanisvaiders@gmail.com>
|
| 573 |
+
krzysiek.pawlik@silvermedia.pl
|
| 574 |
+
Krzysztof Jagiello <me@kjagiello.com>
|
| 575 |
+
Krzysztof Jurewicz <krzysztof.jurewicz@gmail.com>
|
| 576 |
+
Krzysztof Kulewski <kulewski@gmail.com>
|
| 577 |
+
kurtiss@meetro.com
|
| 578 |
+
Lakin Wecker <lakin@structuredabstraction.com>
|
| 579 |
+
Lars Yencken <lars.yencken@gmail.com>
|
| 580 |
+
Lau Bech Lauritzen
|
| 581 |
+
Laurent Luce <https://www.laurentluce.com/>
|
| 582 |
+
Laurent Rahuel <laurent.rahuel@gmail.com>
|
| 583 |
+
lcordier@point45.com
|
| 584 |
+
Leah Culver <leah.culver@gmail.com>
|
| 585 |
+
Leandra Finger <leandra.finger@gmail.com>
|
| 586 |
+
Lee Reilly <lee@leereilly.net>
|
| 587 |
+
Lee Sanghyuck <shlee322@elab.kr>
|
| 588 |
+
Leo "hylje" Honkanen <sealage@gmail.com>
|
| 589 |
+
Leo Shklovskii
|
| 590 |
+
Leo Soto <leo.soto@gmail.com>
|
| 591 |
+
lerouxb@gmail.com
|
| 592 |
+
Lex Berezhny <lex@damoti.com>
|
| 593 |
+
Liang Feng <hutuworm@gmail.com>
|
| 594 |
+
Lily Foote
|
| 595 |
+
limodou
|
| 596 |
+
Lincoln Smith <lincoln.smith@anu.edu.au>
|
| 597 |
+
Liu Yijie <007gzs@gmail.com>
|
| 598 |
+
Loek van Gent <loek@barakken.nl>
|
| 599 |
+
Loïc Bistuer <loic.bistuer@sixmedia.com>
|
| 600 |
+
Lowe Thiderman <lowe.thiderman@gmail.com>
|
| 601 |
+
Luan Pablo <luanpab@gmail.com>
|
| 602 |
+
Lucas Connors <https://www.revolutiontech.ca/>
|
| 603 |
+
Luciano Ramalho
|
| 604 |
+
Lucidiot <lucidiot@brainshit.fr>
|
| 605 |
+
Ludvig Ericson <ludvig.ericson@gmail.com>
|
| 606 |
+
Luis C. Berrocal <luis.berrocal.1942@gmail.com>
|
| 607 |
+
Łukasz Langa <lukasz@langa.pl>
|
| 608 |
+
Łukasz Rekucki <lrekucki@gmail.com>
|
| 609 |
+
Luke Granger-Brown <django@lukegb.com>
|
| 610 |
+
Luke Plant <L.Plant.98@cantab.net>
|
| 611 |
+
Maciej Fijalkowski
|
| 612 |
+
Maciej Wiśniowski <pigletto@gmail.com>
|
| 613 |
+
Mads Jensen <https://github.com/atombrella>
|
| 614 |
+
Makoto Tsuyuki <mtsuyuki@gmail.com>
|
| 615 |
+
Malcolm Tredinnick
|
| 616 |
+
Manav Agarwal <dpsman13016@gmail.com>
|
| 617 |
+
Manuel Saelices <msaelices@yaco.es>
|
| 618 |
+
Manuzhai
|
| 619 |
+
Marc Aymerich Gubern
|
| 620 |
+
Marc Egli <frog32@me.com>
|
| 621 |
+
Marcel Telka <marcel@telka.sk>
|
| 622 |
+
Marcelo Galigniana <marcelogaligniana@gmail.com>
|
| 623 |
+
Marc Fargas <telenieko@telenieko.com>
|
| 624 |
+
Marc Garcia <marc.garcia@accopensys.com>
|
| 625 |
+
Marcin Wróbel
|
| 626 |
+
Marc Remolt <m.remolt@webmasters.de>
|
| 627 |
+
Marc Seguí Coll <metarizard@gmail.com>
|
| 628 |
+
Marc Tamlyn <marc.tamlyn@gmail.com>
|
| 629 |
+
Marc-Aurèle Brothier <ma.brothier@gmail.com>
|
| 630 |
+
Marian Andre <django@andre.sk>
|
| 631 |
+
Marijn Vriens <marijn@metronomo.cl>
|
| 632 |
+
Mario Gonzalez <gonzalemario@gmail.com>
|
| 633 |
+
Mariusz Felisiak <felisiak.mariusz@gmail.com>
|
| 634 |
+
Mark Biggers <biggers@utsl.com>
|
| 635 |
+
Mark Evans <mark@meltdownlabs.com>
|
| 636 |
+
Mark Gensler <mark.gensler@protonmail.com>
|
| 637 |
+
mark@junklight.com
|
| 638 |
+
Mark Lavin <markdlavin@gmail.com>
|
| 639 |
+
Mark Sandstrom <mark@deliciouslynerdy.com>
|
| 640 |
+
Markus Amalthea Magnuson <markus.magnuson@gmail.com>
|
| 641 |
+
Markus Holtermann <https://markusholtermann.eu>
|
| 642 |
+
Marten Kenbeek <marten.knbk+django@gmail.com>
|
| 643 |
+
Marti Raudsepp <marti@juffo.org>
|
| 644 |
+
martin.glueck@gmail.com
|
| 645 |
+
Martin Green
|
| 646 |
+
Martin Kosír <martin@martinkosir.net>
|
| 647 |
+
Martin Mahner <https://www.mahner.org/>
|
| 648 |
+
Martin Maney <http://www.chipy.org/Martin_Maney>
|
| 649 |
+
Martin von Gagern <gagern@google.com>
|
| 650 |
+
Mart Sõmermaa <https://github.com/mrts>
|
| 651 |
+
Marty Alchin <gulopine@gamemusic.org>
|
| 652 |
+
Masashi Shibata <m.shibata1020@gmail.com>
|
| 653 |
+
masonsimon+django@gmail.com
|
| 654 |
+
Massimiliano Ravelli <massimiliano.ravelli@gmail.com>
|
| 655 |
+
Massimo Scamarcia <massimo.scamarcia@gmail.com>
|
| 656 |
+
Mathieu Agopian <mathieu.agopian@gmail.com>
|
| 657 |
+
Matías Bordese
|
| 658 |
+
Matt Boersma <matt@sprout.org>
|
| 659 |
+
Matt Brewer <matt.brewer693@gmail.com>
|
| 660 |
+
Matt Croydon <http://www.postneo.com/>
|
| 661 |
+
Matt Deacalion Stevens <matt@dirtymonkey.co.uk>
|
| 662 |
+
Matt Dennenbaum
|
| 663 |
+
Matthew Flanagan <https://wadofstuff.blogspot.com/>
|
| 664 |
+
Matthew Schinckel <matt@schinckel.net>
|
| 665 |
+
Matthew Somerville <matthew-django@dracos.co.uk>
|
| 666 |
+
Matthew Tretter <m@tthewwithanm.com>
|
| 667 |
+
Matthew Wilkes <matt@matthewwilkes.name>
|
| 668 |
+
Matthias Kestenholz <mk@406.ch>
|
| 669 |
+
Matthias Pronk <django@masida.nl>
|
| 670 |
+
Matt Hoskins <skaffenuk@googlemail.com>
|
| 671 |
+
Matt McClanahan <https://mmcc.cx/>
|
| 672 |
+
Matt Riggott
|
| 673 |
+
Matt Robenolt <m@robenolt.com>
|
| 674 |
+
Mattia Larentis <mattia@laretis.eu>
|
| 675 |
+
Mattia Procopio <promat85@gmail.com>
|
| 676 |
+
Mattias Loverot <mattias@stubin.se>
|
| 677 |
+
mattycakes@gmail.com
|
| 678 |
+
Max Burstein <http://maxburstein.com>
|
| 679 |
+
Max Derkachev <mderk@yandex.ru>
|
| 680 |
+
Max Smolens <msmolens@gmail.com>
|
| 681 |
+
Maxime Lorant <maxime.lorant@gmail.com>
|
| 682 |
+
Maxime Turcotte <maxocub@riseup.net>
|
| 683 |
+
Maximilian Merz <django@mxmerz.de>
|
| 684 |
+
Maximillian Dornseif <md@hudora.de>
|
| 685 |
+
mccutchen@gmail.com
|
| 686 |
+
Meghana Bhange <meghanabhange13@gmail.com>
|
| 687 |
+
Meir Kriheli <http://mksoft.co.il/>
|
| 688 |
+
Michael S. Brown <michael@msbrown.net>
|
| 689 |
+
Michael Hall <mhall1@ualberta.ca>
|
| 690 |
+
Michael Josephson <http://www.sdjournal.com/>
|
| 691 |
+
Michael Lissner <mike@free.law>
|
| 692 |
+
Michael Manfre <mmanfre@gmail.com>
|
| 693 |
+
michael.mcewan@gmail.com
|
| 694 |
+
Michael Placentra II <someone@michaelplacentra2.net>
|
| 695 |
+
Michael Radziej <mir@noris.de>
|
| 696 |
+
Michael Sanders <m.r.sanders@gmail.com>
|
| 697 |
+
Michael Schwarz <michi.schwarz@gmail.com>
|
| 698 |
+
Michael Sinov <sihaelov@gmail.com>
|
| 699 |
+
Michael Thornhill <michael.thornhill@gmail.com>
|
| 700 |
+
Michal Chruszcz <troll@pld-linux.org>
|
| 701 |
+
michal@plovarna.cz
|
| 702 |
+
Michał Modzelewski <michal.modzelewski@gmail.com>
|
| 703 |
+
Mihai Damian <yang_damian@yahoo.com>
|
| 704 |
+
Mihai Preda <mihai_preda@yahoo.com>
|
| 705 |
+
Mikaël Barbero <mikael.barbero nospam at nospam free.fr>
|
| 706 |
+
Mike Axiak <axiak@mit.edu>
|
| 707 |
+
Mike Grouchy <https://mikegrouchy.com/>
|
| 708 |
+
Mike Malone <mjmalone@gmail.com>
|
| 709 |
+
Mike Richardson
|
| 710 |
+
Mike Wiacek <mjwiacek@google.com>
|
| 711 |
+
Mikhail Korobov <kmike84@googlemail.com>
|
| 712 |
+
Mikko Hellsing <mikko@sorl.net>
|
| 713 |
+
Mikołaj Siedlarek <mikolaj.siedlarek@gmail.com>
|
| 714 |
+
milkomeda
|
| 715 |
+
Milton Waddams
|
| 716 |
+
mitakummaa@gmail.com
|
| 717 |
+
mmarshall
|
| 718 |
+
Moayad Mardini <moayad.m@gmail.com>
|
| 719 |
+
Morgan Aubert <morgan.aubert@zoho.com>
|
| 720 |
+
Moritz Sichert <moritz.sichert@googlemail.com>
|
| 721 |
+
Morten Bagai <m@bagai.com>
|
| 722 |
+
msaelices <msaelices@gmail.com>
|
| 723 |
+
msundstr
|
| 724 |
+
Mushtaq Ali <mushtaak@gmail.com>
|
| 725 |
+
Mykola Zamkovoi <nickzam@gmail.com>
|
| 726 |
+
Nadège Michel <michel.nadege@gmail.com>
|
| 727 |
+
Nagy Károly <charlie@rendszergazda.com>
|
| 728 |
+
Nasimul Haque <nasim.haque@gmail.com>
|
| 729 |
+
Nasir Hussain <nasirhjafri@gmail.com>
|
| 730 |
+
Natalia Bidart <nataliabidart@gmail.com>
|
| 731 |
+
Nate Bragg <jonathan.bragg@alum.rpi.edu>
|
| 732 |
+
Nathan Gaberel <nathan@gnab.fr>
|
| 733 |
+
Neal Norwitz <nnorwitz@google.com>
|
| 734 |
+
Nebojša Dorđević
|
| 735 |
+
Ned Batchelder <https://nedbatchelder.com/>
|
| 736 |
+
Nena Kojadin <nena@kiberpipa.org>
|
| 737 |
+
Niall Dalton <niall.dalton12@gmail.com>
|
| 738 |
+
Niall Kelly <duke.sam.vimes@gmail.com>
|
| 739 |
+
Nick Efford <nick@efford.org>
|
| 740 |
+
Nick Lane <nick.lane.au@gmail.com>
|
| 741 |
+
Nick Pope <nick@nickpope.me.uk>
|
| 742 |
+
Nick Presta <nick@nickpresta.ca>
|
| 743 |
+
Nick Sandford <nick.sandford@gmail.com>
|
| 744 |
+
Nick Sarbicki <nick.a.sarbicki@gmail.com>
|
| 745 |
+
Niclas Olofsson <n@niclasolofsson.se>
|
| 746 |
+
Nicola Larosa <nico@teknico.net>
|
| 747 |
+
Nicolas Lara <nicolaslara@gmail.com>
|
| 748 |
+
Nicolas Noé <nicolas@niconoe.eu>
|
| 749 |
+
Nikita Marchant <nikita.marchant@gmail.com>
|
| 750 |
+
Nikita Sobolev <mail@sobolevn.me>
|
| 751 |
+
Niran Babalola <niran@niran.org>
|
| 752 |
+
Nis Jørgensen <nis@superlativ.dk>
|
| 753 |
+
Nowell Strite <https://nowell.strite.org/>
|
| 754 |
+
Nuno Mariz <nmariz@gmail.com>
|
| 755 |
+
Octavio Peri <octaperi@gmail.com>
|
| 756 |
+
oggie rob <oz.robharvey@gmail.com>
|
| 757 |
+
oggy <ognjen.maric@gmail.com>
|
| 758 |
+
Oliver Beattie <oliver@obeattie.com>
|
| 759 |
+
Oliver Rutherfurd <http://rutherfurd.net/>
|
| 760 |
+
Olivier Le Thanh Duong <olivier@lethanh.be>
|
| 761 |
+
Olivier Sels <olivier.sels@gmail.com>
|
| 762 |
+
Olivier Tabone <olivier.tabone@ripplemotion.fr>
|
| 763 |
+
Orestis Markou <orestis@orestis.gr>
|
| 764 |
+
Orne Brocaar <http://brocaar.com/>
|
| 765 |
+
Oscar Ramirez <tuxskar@gmail.com>
|
| 766 |
+
Ossama M. Khayat <okhayat@yahoo.com>
|
| 767 |
+
Owen Griffiths
|
| 768 |
+
Ömer Faruk Abacı <https://github.com/omerfarukabaci/>
|
| 769 |
+
Pablo Martín <goinnn@gmail.com>
|
| 770 |
+
Panos Laganakos <panos.laganakos@gmail.com>
|
| 771 |
+
Paolo Melchiorre <paolo@melchiorre.org>
|
| 772 |
+
Pascal Hartig <phartig@rdrei.net>
|
| 773 |
+
Pascal Varet
|
| 774 |
+
Patrik Sletmo <patrik.sletmo@gmail.com>
|
| 775 |
+
Paul Bissex <http://e-scribe.com/>
|
| 776 |
+
Paul Collier <paul@paul-collier.com>
|
| 777 |
+
Paul Collins <paul.collins.iii@gmail.com>
|
| 778 |
+
Paul Donohue <django@PaulSD.com>
|
| 779 |
+
Paul Lanier <planier@google.com>
|
| 780 |
+
Paul McLanahan <paul@mclanahan.net>
|
| 781 |
+
Paul McMillan <Paul@McMillan.ws>
|
| 782 |
+
Paulo Poiati <paulogpoiati@gmail.com>
|
| 783 |
+
Paulo Scardine <paulo@scardine.com.br>
|
| 784 |
+
Paul Smith <blinkylights23@gmail.com>
|
| 785 |
+
Pavel Kulikov <kulikovpavel@gmail.com>
|
| 786 |
+
pavithran s <pavithran.s@gmail.com>
|
| 787 |
+
Pavlo Kapyshin <i@93z.org>
|
| 788 |
+
permonik@mesias.brnonet.cz
|
| 789 |
+
Petar Marić <http://www.petarmaric.com/>
|
| 790 |
+
Pete Crosier <pete.crosier@gmail.com>
|
| 791 |
+
peter@mymart.com
|
| 792 |
+
Peter Sheats <sheats@gmail.com>
|
| 793 |
+
Peter van Kampen
|
| 794 |
+
Peter Zsoldos <http://zsoldosp.eu>
|
| 795 |
+
Pete Shinners <pete@shinners.org>
|
| 796 |
+
Petr Marhoun <petr.marhoun@gmail.com>
|
| 797 |
+
Petter Strandmark
|
| 798 |
+
pgross@thoughtworks.com
|
| 799 |
+
phaedo <http://phaedo.cx/>
|
| 800 |
+
phil.h.smith@gmail.com
|
| 801 |
+
Philip Lindborg <philip.lindborg@gmail.com>
|
| 802 |
+
Philippe Raoult <philippe.raoult@n2nsoft.com>
|
| 803 |
+
phil@produxion.net
|
| 804 |
+
Piotr Jakimiak <piotr.jakimiak@gmail.com>
|
| 805 |
+
Piotr Lewandowski <piotr.lewandowski@gmail.com>
|
| 806 |
+
plisk
|
| 807 |
+
polpak@yahoo.com
|
| 808 |
+
pradeep.gowda@gmail.com
|
| 809 |
+
Preston Holmes <preston@ptone.com>
|
| 810 |
+
Preston Timmons <prestontimmons@gmail.com>
|
| 811 |
+
Priyansh Saxena <askpriyansh@gmail.com>
|
| 812 |
+
Przemysław Buczkowski <przemub@przemub.pl>
|
| 813 |
+
Przemysław Suliga <http://suligap.net>
|
| 814 |
+
Qi Zhao <zhaoqi99@outlook.com>
|
| 815 |
+
Rachel Tobin <rmtobin@me.com>
|
| 816 |
+
Rachel Willmer <http://www.willmer.com/kb/>
|
| 817 |
+
Radek Švarz <https://www.svarz.cz/translate/>
|
| 818 |
+
Rafael Giebisch <rafael@giebisch-mail.de>
|
| 819 |
+
Raffaele Salmaso <raffaele@salmaso.org>
|
| 820 |
+
Rahmat Faisal <mad.skidipap@gmail.com>
|
| 821 |
+
Rajesh Dhawan <rajesh.dhawan@gmail.com>
|
| 822 |
+
Ramez Ashraf <ramezashraf@gmail.com>
|
| 823 |
+
Ramil Yanbulatov <rayman1104@gmail.com>
|
| 824 |
+
Ramin Farajpour Cami <ramin.blackhat@gmail.com>
|
| 825 |
+
Ramiro Morales <ramiro@rmorales.net>
|
| 826 |
+
Ramon Saraiva <ramonsaraiva@gmail.com>
|
| 827 |
+
Ram Rachum <ram@rachum.com>
|
| 828 |
+
Randy Barlow <randy@electronsweatshop.com>
|
| 829 |
+
Raphaël Barrois <raphael.barrois@m4x.org>
|
| 830 |
+
Raphael Michel <mail@raphaelmichel.de>
|
| 831 |
+
Raúl Cumplido <raulcumplido@gmail.com>
|
| 832 |
+
Rebecca Smith <rebkwok@gmail.com>
|
| 833 |
+
Remco Wendt <remco.wendt@gmail.com>
|
| 834 |
+
Renaud Parent <renaud.parent@gmail.com>
|
| 835 |
+
Renbi Yu <averybigant@gmail.com>
|
| 836 |
+
Reza Mohammadi <reza@zeerak.ir>
|
| 837 |
+
rhettg@gmail.com
|
| 838 |
+
Ricardo Javier Cárdenes Medina <ricardo.cardenes@gmail.com>
|
| 839 |
+
ricardojbarrios@gmail.com
|
| 840 |
+
Riccardo Di Virgilio
|
| 841 |
+
Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
|
| 842 |
+
Richard Davies <richard.davies@elastichosts.com>
|
| 843 |
+
Richard House <Richard.House@i-logue.com>
|
| 844 |
+
Rick Wagner <rwagner@physics.ucsd.edu>
|
| 845 |
+
Rigel Di Scala <rigel.discala@propylon.com>
|
| 846 |
+
Robert Coup
|
| 847 |
+
Robert Myers <myer0052@gmail.com>
|
| 848 |
+
Roberto Aguilar <roberto@baremetal.io>
|
| 849 |
+
Robert Rock Howard <http://djangomojo.com/>
|
| 850 |
+
Robert Wittams
|
| 851 |
+
Rob Golding-Day <rob@golding-day.com>
|
| 852 |
+
Rob Hudson <https://rob.cogit8.org/>
|
| 853 |
+
Rob Nguyen <tienrobertnguyenn@gmail.com>
|
| 854 |
+
Robin Munn <http://www.geekforgod.com/>
|
| 855 |
+
Rodrigo Pinheiro Marques de Araújo <fenrrir@gmail.com>
|
| 856 |
+
Rohith P R <https://rohithpr.com>
|
| 857 |
+
Romain Garrigues <romain.garrigues.cs@gmail.com>
|
| 858 |
+
Ronnie van den Crommenacker
|
| 859 |
+
Ronny Haryanto <https://ronny.haryan.to/>
|
| 860 |
+
Ross Poulton <ross@rossp.org>
|
| 861 |
+
Roxane Bellot <https://github.com/roxanebellot/>
|
| 862 |
+
Rozza <ross.lawley@gmail.com>
|
| 863 |
+
Rudolph Froger <rfroger@estrate.nl>
|
| 864 |
+
Rudy Mutter
|
| 865 |
+
Rune Rønde Laursen <runerl@skjoldhoej.dk>
|
| 866 |
+
Russell Cloran <russell@rucus.net>
|
| 867 |
+
Russell Keith-Magee <russell@keith-magee.com>
|
| 868 |
+
Russ Webber
|
| 869 |
+
Ryan Hall <ryanhall989@gmail.com>
|
| 870 |
+
Ryan Heard <ryanwheard@gmail.com>
|
| 871 |
+
ryankanno
|
| 872 |
+
Ryan Kelly <ryan@rfk.id.au>
|
| 873 |
+
Ryan Niemeyer <https://profiles.google.com/ryan.niemeyer/about>
|
| 874 |
+
Ryan Petrello <ryan@ryanpetrello.com>
|
| 875 |
+
Ryan Rubin <ryanmrubin@gmail.com>
|
| 876 |
+
Ryno Mathee <rmathee@gmail.com>
|
| 877 |
+
Sachin Jat <sanch.jat@gmail.com>
|
| 878 |
+
Sage M. Abdullah <https://github.com/laymonage>
|
| 879 |
+
Sam Newman <http://www.magpiebrain.com/>
|
| 880 |
+
Sander Dijkhuis <sander.dijkhuis@gmail.com>
|
| 881 |
+
Sanket Saurav <sanketsaurav@gmail.com>
|
| 882 |
+
Sanyam Khurana <sanyam.khurana01@gmail.com>
|
| 883 |
+
Sarah Boyce <https://github.com/sarahboyce>
|
| 884 |
+
Sarthak Mehrish <sarthakmeh03@gmail.com>
|
| 885 |
+
schwank@gmail.com
|
| 886 |
+
Scot Hacker <shacker@birdhouse.org>
|
| 887 |
+
Scott Barr <scott@divisionbyzero.com.au>
|
| 888 |
+
Scott Cranfill <scott@scottcranfill.com>
|
| 889 |
+
Scott Fitsimones <scott@airgara.ge>
|
| 890 |
+
Scott Pashley <github@scottpashley.co.uk>
|
| 891 |
+
scott@staplefish.com
|
| 892 |
+
Sean Brant
|
| 893 |
+
Sebastian Hillig <sebastian.hillig@gmail.com>
|
| 894 |
+
Sebastian Spiegel <https://www.tivix.com/>
|
| 895 |
+
Segyo Myung <myungsekyo@gmail.com>
|
| 896 |
+
Selwin Ong <selwin@ui.co.id>
|
| 897 |
+
Sengtha Chay <sengtha@e-khmer.com>
|
| 898 |
+
Senko Rašić <senko.rasic@dobarkod.hr>
|
| 899 |
+
serbaut@gmail.com
|
| 900 |
+
Sergei Maertens <sergeimaertens@gmail.com>
|
| 901 |
+
Sergey Fedoseev <fedoseev.sergey@gmail.com>
|
| 902 |
+
Sergey Kolosov <m17.admin@gmail.com>
|
| 903 |
+
Seth Hill <sethrh@gmail.com>
|
| 904 |
+
Shai Berger <shai@platonix.com>
|
| 905 |
+
Shannon -jj Behrens <https://www.jjinux.com/>
|
| 906 |
+
Shawn Milochik <shawn@milochik.com>
|
| 907 |
+
Shreya Bamne <shreya.bamne@gmail.com>
|
| 908 |
+
Silvan Spross <silvan.spross@gmail.com>
|
| 909 |
+
Simeon Visser <http://simeonvisser.com>
|
| 910 |
+
Simon Blanchard
|
| 911 |
+
Simon Charette <charette.s@gmail.com>
|
| 912 |
+
Simon Greenhill <dev@simon.net.nz>
|
| 913 |
+
Simon Litchfield <simon@quo.com.au>
|
| 914 |
+
Simon Meers <simon@simonmeers.com>
|
| 915 |
+
Simon Williams
|
| 916 |
+
Simon Willison <simon@simonwillison.net>
|
| 917 |
+
Sjoerd Job Postmus
|
| 918 |
+
Slawek Mikula <slawek dot mikula at gmail dot com>
|
| 919 |
+
sloonz <simon.lipp@insa-lyon.fr>
|
| 920 |
+
smurf@smurf.noris.de
|
| 921 |
+
sopel
|
| 922 |
+
Sreehari K V <sreeharivijayan619@gmail.com>
|
| 923 |
+
Sridhar Marella <sridhar562345@gmail.com>
|
| 924 |
+
Srinivas Reddy Thatiparthy <thatiparthysreenivas@gmail.com>
|
| 925 |
+
Stanislas Guerra <stan@slashdev.me>
|
| 926 |
+
Stanislaus Madueke
|
| 927 |
+
Stanislav Karpov <work@stkrp.ru>
|
| 928 |
+
starrynight <cmorgh@gmail.com>
|
| 929 |
+
Stefan R. Filipek
|
| 930 |
+
Stefane Fermgier <sf@fermigier.com>
|
| 931 |
+
Stefano Rivera <stefano@rivera.za.net>
|
| 932 |
+
Stéphane Raimbault <stephane.raimbault@gmail.com>
|
| 933 |
+
Stephan Jaekel <steph@rdev.info>
|
| 934 |
+
Stephen Burrows <stephen.r.burrows@gmail.com>
|
| 935 |
+
Steven L. Smith (fvox13) <steven@stevenlsmith.com>
|
| 936 |
+
Steven Noorbergen (Xaroth) <xaroth+django@xaroth.nl>
|
| 937 |
+
Stuart Langridge <https://www.kryogenix.org/>
|
| 938 |
+
Subhav Gautam <subhavgautam@yahoo.co.uk>
|
| 939 |
+
Sujay S Kumar <sujay.skumar141295@gmail.com>
|
| 940 |
+
Sune Kirkeby <https://ibofobi.dk/>
|
| 941 |
+
Sung-Jin Hong <serialx.net@gmail.com>
|
| 942 |
+
SuperJared
|
| 943 |
+
Susan Tan <susan.tan.fleckerl@gmail.com>
|
| 944 |
+
Sutrisno Efendi <kangfend@gmail.com>
|
| 945 |
+
Swaroop C H <http://www.swaroopch.info>
|
| 946 |
+
Szilveszter Farkas <szilveszter.farkas@gmail.com>
|
| 947 |
+
Taavi Teska <taaviteska@gmail.com>
|
| 948 |
+
Tai Lee <real.human@mrmachine.net>
|
| 949 |
+
Takashi Matsuo <matsuo.takashi@gmail.com>
|
| 950 |
+
Tareque Hossain <http://www.codexn.com>
|
| 951 |
+
Taylor Mitchell <taylor.mitchell@gmail.com>
|
| 952 |
+
Terry Huang <terryh.tp@gmail.com>
|
| 953 |
+
thebjorn <bp@datakortet.no>
|
| 954 |
+
Thejaswi Puthraya <thejaswi.puthraya@gmail.com>
|
| 955 |
+
Thijs van Dien <thijs@vandien.net>
|
| 956 |
+
Thom Wiggers
|
| 957 |
+
Thomas Chaumeny <t.chaumeny@gmail.com>
|
| 958 |
+
Thomas Güttler <hv@tbz-pariv.de>
|
| 959 |
+
Thomas Kerpe <thomas@kerpe.net>
|
| 960 |
+
Thomas Sorrel
|
| 961 |
+
Thomas Steinacher <http://www.eggdrop.ch/>
|
| 962 |
+
Thomas Stromberg <tstromberg@google.com>
|
| 963 |
+
Thomas Tanner <tanner@gmx.net>
|
| 964 |
+
tibimicu@gmx.net
|
| 965 |
+
Ties Jan Hefting <hello@tiesjan.com>
|
| 966 |
+
Tim Allen <tim@pyphilly.org>
|
| 967 |
+
Tim Givois <tim.givois.mendez@gmail.com>
|
| 968 |
+
Tim Graham <timograham@gmail.com>
|
| 969 |
+
Tim Heap <tim@timheap.me>
|
| 970 |
+
Tim McCurrach <tim.mccurrach@gmail.com>
|
| 971 |
+
Tim Saylor <tim.saylor@gmail.com>
|
| 972 |
+
Tobias Kunze <rixx@cutebit.de>
|
| 973 |
+
Tobias McNulty <https://www.caktusgroup.com/blog/>
|
| 974 |
+
tobias@neuyork.de
|
| 975 |
+
Todd O'Bryan <toddobryan@mac.com>
|
| 976 |
+
Tom Carrick <https://www.carrick.eu>
|
| 977 |
+
Tom Christie <tom@tomchristie.com>
|
| 978 |
+
Tom Forbes <tom@tomforb.es>
|
| 979 |
+
Tom Insam
|
| 980 |
+
Tom Tobin
|
| 981 |
+
Tom Wojcik <me@tomwojcik.com>
|
| 982 |
+
Tomáš Ehrlich <tomas.ehrlich@gmail.com>
|
| 983 |
+
Tomáš Kopeček <permonik@m6.cz>
|
| 984 |
+
Tome Cvitan <tome@cvitan.com>
|
| 985 |
+
Tomek Paczkowski <tomek@hauru.eu>
|
| 986 |
+
Tomer Chachamu
|
| 987 |
+
Tommy Beadle <tbeadle@gmail.com>
|
| 988 |
+
Tore Lundqvist <tore.lundqvist@gmail.com>
|
| 989 |
+
torne-django@wolfpuppy.org.uk
|
| 990 |
+
Travis Cline <travis.cline@gmail.com>
|
| 991 |
+
Travis Pinney
|
| 992 |
+
Travis Swicegood <travis@domain51.com>
|
| 993 |
+
Travis Terry <tdterry7@gmail.com>
|
| 994 |
+
Trevor Caira <trevor@caira.com>
|
| 995 |
+
Trey Long <trey@ktrl.com>
|
| 996 |
+
tstromberg@google.com
|
| 997 |
+
tt@gurgle.no
|
| 998 |
+
Tyler Tarabula <tyler.tarabula@gmail.com>
|
| 999 |
+
Tyson Clugg <tyson@clugg.net>
|
| 1000 |
+
Tyson Tate <tyson@fallingbullets.com>
|
| 1001 |
+
Unai Zalakain <unai@gisa-elkartea.org>
|
| 1002 |
+
Valentina Mukhamedzhanova <umirra@gmail.com>
|
| 1003 |
+
valtron
|
| 1004 |
+
Vasiliy Stavenko <stavenko@gmail.com>
|
| 1005 |
+
Vasil Vangelovski
|
| 1006 |
+
Vibhu Agarwal <vibhu-agarwal.github.io>
|
| 1007 |
+
Victor Andrée
|
| 1008 |
+
viestards.lists@gmail.com
|
| 1009 |
+
Viktor Danyliuk <v.v.danyliuk@gmail.com>
|
| 1010 |
+
Viktor Grabov <viktor@grabov.ru>
|
| 1011 |
+
Ville Säävuori <https://www.unessa.net/>
|
| 1012 |
+
Vinay Karanam <https://github.com/vinayinvicible>
|
| 1013 |
+
Vinay Sajip <vinay_sajip@yahoo.co.uk>
|
| 1014 |
+
Vincent Foley <vfoleybourgon@yahoo.ca>
|
| 1015 |
+
Vinny Do <vdo.code@gmail.com>
|
| 1016 |
+
Vitaly Babiy <vbabiy86@gmail.com>
|
| 1017 |
+
Vitaliy Yelnik <velnik@gmail.com>
|
| 1018 |
+
Vladimir Kuzma <vladimirkuzma.ch@gmail.com>
|
| 1019 |
+
Vlado <vlado@labath.org>
|
| 1020 |
+
Vsevolod Solovyov
|
| 1021 |
+
Vytis Banaitis <vytis.banaitis@gmail.com>
|
| 1022 |
+
wam-djangobug@wamber.net
|
| 1023 |
+
Wang Chun <wangchun@exoweb.net>
|
| 1024 |
+
Warren Smith <warren@wandrsmith.net>
|
| 1025 |
+
Waylan Limberg <waylan@gmail.com>
|
| 1026 |
+
Wiktor Kołodziej <wiktor@pykonik.org>
|
| 1027 |
+
Wiley Kestner <wiley.kestner@gmail.com>
|
| 1028 |
+
Wiliam Alves de Souza <wiliamsouza83@gmail.com>
|
| 1029 |
+
Will Ayd <william.ayd@icloud.com>
|
| 1030 |
+
William Schwartz <wkschwartz@gmail.com>
|
| 1031 |
+
Will Hardy <django@willhardy.com.au>
|
| 1032 |
+
Wilson Miner <wminer@gmail.com>
|
| 1033 |
+
Wim Glenn <hey@wimglenn.com>
|
| 1034 |
+
wojtek
|
| 1035 |
+
Wu Haotian <whtsky@gmail.com>
|
| 1036 |
+
Xavier Francisco <xavier.n.francisco@gmail.com>
|
| 1037 |
+
Xia Kai <https://blog.xiaket.org/>
|
| 1038 |
+
Yann Fouillat <gagaro42@gmail.com>
|
| 1039 |
+
Yann Malet
|
| 1040 |
+
Yash Jhunjhunwala
|
| 1041 |
+
Yasushi Masuda <whosaysni@gmail.com>
|
| 1042 |
+
ye7cakf02@sneakemail.com
|
| 1043 |
+
ymasuda@ethercube.com
|
| 1044 |
+
Yoong Kang Lim <yoongkang.lim@gmail.com>
|
| 1045 |
+
Yusuke Miyazaki <miyazaki.dev@gmail.com>
|
| 1046 |
+
yyyyyyyan <contact@yyyyyyyan.tech>
|
| 1047 |
+
Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
|
| 1048 |
+
Zachary Voase <zacharyvoase@gmail.com>
|
| 1049 |
+
Zach Liu <zachliu@gmail.com>
|
| 1050 |
+
Zach Thompson <zthompson47@gmail.com>
|
| 1051 |
+
Zain Memon
|
| 1052 |
+
Zain Patel <zain.patel06@gmail.com>
|
| 1053 |
+
Zak Johnson <zakj@nox.cx>
|
| 1054 |
+
Žan Anderle <zan.anderle@gmail.com>
|
| 1055 |
+
Zbigniew Siciarz <zbigniew@siciarz.net>
|
| 1056 |
+
zegor
|
| 1057 |
+
Zeynel Özdemir <ozdemir.zynl@gmail.com>
|
| 1058 |
+
Zlatko Mašek <zlatko.masek@gmail.com>
|
| 1059 |
+
zriv <https://github.com/zriv>
|
| 1060 |
+
<Please alphabetize new entries>
|
| 1061 |
+
|
| 1062 |
+
A big THANK YOU goes to:
|
| 1063 |
+
|
| 1064 |
+
Rob Curley and Ralph Gage for letting us open-source Django.
|
| 1065 |
+
|
| 1066 |
+
Frank Wiles for making excellent arguments for open-sourcing, and for
|
| 1067 |
+
his sage sysadmin advice.
|
| 1068 |
+
|
| 1069 |
+
Ian Bicking for convincing Adrian to ditch code generation.
|
| 1070 |
+
|
| 1071 |
+
Mark Pilgrim for "Dive Into Python" (https://www.diveinto.org/python3/).
|
| 1072 |
+
|
| 1073 |
+
Guido van Rossum for creating Python.
|
testbed/django__django/CONTRIBUTING.rst
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
======================
|
| 2 |
+
Contributing to Django
|
| 3 |
+
======================
|
| 4 |
+
|
| 5 |
+
As an open source project, Django welcomes contributions of many forms.
|
| 6 |
+
|
| 7 |
+
Examples of contributions include:
|
| 8 |
+
|
| 9 |
+
* Code patches
|
| 10 |
+
* Documentation improvements
|
| 11 |
+
* Bug reports and patch reviews
|
| 12 |
+
|
| 13 |
+
Extensive contribution guidelines are available in the repository at
|
| 14 |
+
``docs/internals/contributing/``, or online at:
|
| 15 |
+
|
| 16 |
+
https://docs.djangoproject.com/en/dev/internals/contributing/
|
| 17 |
+
|
| 18 |
+
**Warning: non-trivial pull requests (anything more than fixing a typo) without
|
| 19 |
+
Trac tickets will be closed!** `Please file a ticket`__ to suggest changes.
|
| 20 |
+
|
| 21 |
+
__ https://code.djangoproject.com/newticket
|
| 22 |
+
|
| 23 |
+
Django uses Trac to keep track of bugs, feature requests, and associated
|
| 24 |
+
patches because GitHub doesn't provide adequate tooling for its community.
|
| 25 |
+
Patches can be submitted as pull requests, but if you don't file a ticket,
|
| 26 |
+
it's unlikely that we'll notice your contribution.
|
| 27 |
+
|
| 28 |
+
Code of Conduct
|
| 29 |
+
===============
|
| 30 |
+
|
| 31 |
+
As a contributor, you can help us keep the Django community open and inclusive.
|
| 32 |
+
Please read and follow our `Code of Conduct <https://www.djangoproject.com/conduct/>`_.
|
testbed/django__django/Gruntfile.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use strict';
|
| 2 |
+
|
| 3 |
+
const globalThreshold = 50; // Global code coverage threshold (as a percentage)
|
| 4 |
+
|
| 5 |
+
module.exports = function(grunt) {
|
| 6 |
+
grunt.initConfig({
|
| 7 |
+
qunit: {
|
| 8 |
+
all: ['js_tests/tests.html']
|
| 9 |
+
}
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
grunt.loadNpmTasks('grunt-contrib-qunit');
|
| 13 |
+
grunt.registerTask('test', ['qunit']);
|
| 14 |
+
grunt.registerTask('default', ['test']);
|
| 15 |
+
};
|
testbed/django__django/INSTALL
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Thanks for downloading Django.
|
| 2 |
+
|
| 3 |
+
To install it, make sure you have Python 3.10 or greater installed. Then run
|
| 4 |
+
this command from the command prompt:
|
| 5 |
+
|
| 6 |
+
python -m pip install .
|
| 7 |
+
|
| 8 |
+
For more detailed instructions, see docs/intro/install.txt.
|
testbed/django__django/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) Django Software Foundation and individual contributors.
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without modification,
|
| 5 |
+
are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright notice,
|
| 8 |
+
this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of Django nor the names of its contributors may be used
|
| 15 |
+
to endorse or promote products derived from this software without
|
| 16 |
+
specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 19 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 20 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 22 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 23 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 25 |
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 26 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 27 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
testbed/django__django/LICENSE.python
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
LICENSE for details.
|
| 3 |
+
|
| 4 |
+
Django includes code from the Python standard library, which is licensed under
|
| 5 |
+
the Python license, a permissive open source license. The copyright and license
|
| 6 |
+
is included below for compliance with Python's terms.
|
| 7 |
+
|
| 8 |
+
----------------------------------------------------------------------
|
| 9 |
+
|
| 10 |
+
Copyright (c) 2001-present Python Software Foundation; All Rights Reserved
|
| 11 |
+
|
| 12 |
+
A. HISTORY OF THE SOFTWARE
|
| 13 |
+
==========================
|
| 14 |
+
|
| 15 |
+
Python was created in the early 1990s by Guido van Rossum at Stichting
|
| 16 |
+
Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands
|
| 17 |
+
as a successor of a language called ABC. Guido remains Python's
|
| 18 |
+
principal author, although it includes many contributions from others.
|
| 19 |
+
|
| 20 |
+
In 1995, Guido continued his work on Python at the Corporation for
|
| 21 |
+
National Research Initiatives (CNRI, see http://www.cnri.reston.va.us)
|
| 22 |
+
in Reston, Virginia where he released several versions of the
|
| 23 |
+
software.
|
| 24 |
+
|
| 25 |
+
In May 2000, Guido and the Python core development team moved to
|
| 26 |
+
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
|
| 27 |
+
year, the PythonLabs team moved to Digital Creations, which became
|
| 28 |
+
Zope Corporation. In 2001, the Python Software Foundation (PSF, see
|
| 29 |
+
https://www.python.org/psf/) was formed, a non-profit organization
|
| 30 |
+
created specifically to own Python-related Intellectual Property.
|
| 31 |
+
Zope Corporation was a sponsoring member of the PSF.
|
| 32 |
+
|
| 33 |
+
All Python releases are Open Source (see http://www.opensource.org for
|
| 34 |
+
the Open Source Definition). Historically, most, but not all, Python
|
| 35 |
+
releases have also been GPL-compatible; the table below summarizes
|
| 36 |
+
the various releases.
|
| 37 |
+
|
| 38 |
+
Release Derived Year Owner GPL-
|
| 39 |
+
from compatible? (1)
|
| 40 |
+
|
| 41 |
+
0.9.0 thru 1.2 1991-1995 CWI yes
|
| 42 |
+
1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
|
| 43 |
+
1.6 1.5.2 2000 CNRI no
|
| 44 |
+
2.0 1.6 2000 BeOpen.com no
|
| 45 |
+
1.6.1 1.6 2001 CNRI yes (2)
|
| 46 |
+
2.1 2.0+1.6.1 2001 PSF no
|
| 47 |
+
2.0.1 2.0+1.6.1 2001 PSF yes
|
| 48 |
+
2.1.1 2.1+2.0.1 2001 PSF yes
|
| 49 |
+
2.1.2 2.1.1 2002 PSF yes
|
| 50 |
+
2.1.3 2.1.2 2002 PSF yes
|
| 51 |
+
2.2 and above 2.1.1 2001-now PSF yes
|
| 52 |
+
|
| 53 |
+
Footnotes:
|
| 54 |
+
|
| 55 |
+
(1) GPL-compatible doesn't mean that we're distributing Python under
|
| 56 |
+
the GPL. All Python licenses, unlike the GPL, let you distribute
|
| 57 |
+
a modified version without making your changes open source. The
|
| 58 |
+
GPL-compatible licenses make it possible to combine Python with
|
| 59 |
+
other software that is released under the GPL; the others don't.
|
| 60 |
+
|
| 61 |
+
(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
|
| 62 |
+
because its license has a choice of law clause. According to
|
| 63 |
+
CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
|
| 64 |
+
is "not incompatible" with the GPL.
|
| 65 |
+
|
| 66 |
+
Thanks to the many outside volunteers who have worked under Guido's
|
| 67 |
+
direction to make these releases possible.
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
|
| 71 |
+
===============================================================
|
| 72 |
+
|
| 73 |
+
Python software and documentation are licensed under the
|
| 74 |
+
Python Software Foundation License Version 2.
|
| 75 |
+
|
| 76 |
+
Starting with Python 3.8.6, examples, recipes, and other code in
|
| 77 |
+
the documentation are dual licensed under the PSF License Version 2
|
| 78 |
+
and the Zero-Clause BSD license.
|
| 79 |
+
|
| 80 |
+
Some software incorporated into Python is under different licenses.
|
| 81 |
+
The licenses are listed with code falling under that license.
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
|
| 85 |
+
--------------------------------------------
|
| 86 |
+
|
| 87 |
+
1. This LICENSE AGREEMENT is between the Python Software Foundation
|
| 88 |
+
("PSF"), and the Individual or Organization ("Licensee") accessing and
|
| 89 |
+
otherwise using this software ("Python") in source or binary form and
|
| 90 |
+
its associated documentation.
|
| 91 |
+
|
| 92 |
+
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
| 93 |
+
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
|
| 94 |
+
analyze, test, perform and/or display publicly, prepare derivative works,
|
| 95 |
+
distribute, and otherwise use Python alone or in any derivative version,
|
| 96 |
+
provided, however, that PSF's License Agreement and PSF's notice of copyright,
|
| 97 |
+
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
| 98 |
+
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Python Software Foundation;
|
| 99 |
+
All Rights Reserved" are retained in Python alone or in any derivative version
|
| 100 |
+
prepared by Licensee.
|
| 101 |
+
|
| 102 |
+
3. In the event Licensee prepares a derivative work that is based on
|
| 103 |
+
or incorporates Python or any part thereof, and wants to make
|
| 104 |
+
the derivative work available to others as provided herein, then
|
| 105 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 106 |
+
the changes made to Python.
|
| 107 |
+
|
| 108 |
+
4. PSF is making Python available to Licensee on an "AS IS"
|
| 109 |
+
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 110 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
|
| 111 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 112 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
|
| 113 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 114 |
+
|
| 115 |
+
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
| 116 |
+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
| 117 |
+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
|
| 118 |
+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 119 |
+
|
| 120 |
+
6. This License Agreement will automatically terminate upon a material
|
| 121 |
+
breach of its terms and conditions.
|
| 122 |
+
|
| 123 |
+
7. Nothing in this License Agreement shall be deemed to create any
|
| 124 |
+
relationship of agency, partnership, or joint venture between PSF and
|
| 125 |
+
Licensee. This License Agreement does not grant permission to use PSF
|
| 126 |
+
trademarks or trade name in a trademark sense to endorse or promote
|
| 127 |
+
products or services of Licensee, or any third party.
|
| 128 |
+
|
| 129 |
+
8. By copying, installing or otherwise using Python, Licensee
|
| 130 |
+
agrees to be bound by the terms and conditions of this License
|
| 131 |
+
Agreement.
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
|
| 135 |
+
-------------------------------------------
|
| 136 |
+
|
| 137 |
+
BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
|
| 138 |
+
|
| 139 |
+
1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
|
| 140 |
+
office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
|
| 141 |
+
Individual or Organization ("Licensee") accessing and otherwise using
|
| 142 |
+
this software in source or binary form and its associated
|
| 143 |
+
documentation ("the Software").
|
| 144 |
+
|
| 145 |
+
2. Subject to the terms and conditions of this BeOpen Python License
|
| 146 |
+
Agreement, BeOpen hereby grants Licensee a non-exclusive,
|
| 147 |
+
royalty-free, world-wide license to reproduce, analyze, test, perform
|
| 148 |
+
and/or display publicly, prepare derivative works, distribute, and
|
| 149 |
+
otherwise use the Software alone or in any derivative version,
|
| 150 |
+
provided, however, that the BeOpen Python License is retained in the
|
| 151 |
+
Software, alone or in any derivative version prepared by Licensee.
|
| 152 |
+
|
| 153 |
+
3. BeOpen is making the Software available to Licensee on an "AS IS"
|
| 154 |
+
basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 155 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
|
| 156 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 157 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
|
| 158 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 159 |
+
|
| 160 |
+
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
|
| 161 |
+
SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
|
| 162 |
+
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
|
| 163 |
+
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 164 |
+
|
| 165 |
+
5. This License Agreement will automatically terminate upon a material
|
| 166 |
+
breach of its terms and conditions.
|
| 167 |
+
|
| 168 |
+
6. This License Agreement shall be governed by and interpreted in all
|
| 169 |
+
respects by the law of the State of California, excluding conflict of
|
| 170 |
+
law provisions. Nothing in this License Agreement shall be deemed to
|
| 171 |
+
create any relationship of agency, partnership, or joint venture
|
| 172 |
+
between BeOpen and Licensee. This License Agreement does not grant
|
| 173 |
+
permission to use BeOpen trademarks or trade names in a trademark
|
| 174 |
+
sense to endorse or promote products or services of Licensee, or any
|
| 175 |
+
third party. As an exception, the "BeOpen Python" logos available at
|
| 176 |
+
http://www.pythonlabs.com/logos.html may be used according to the
|
| 177 |
+
permissions granted on that web page.
|
| 178 |
+
|
| 179 |
+
7. By copying, installing or otherwise using the software, Licensee
|
| 180 |
+
agrees to be bound by the terms and conditions of this License
|
| 181 |
+
Agreement.
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
|
| 185 |
+
---------------------------------------
|
| 186 |
+
|
| 187 |
+
1. This LICENSE AGREEMENT is between the Corporation for National
|
| 188 |
+
Research Initiatives, having an office at 1895 Preston White Drive,
|
| 189 |
+
Reston, VA 20191 ("CNRI"), and the Individual or Organization
|
| 190 |
+
("Licensee") accessing and otherwise using Python 1.6.1 software in
|
| 191 |
+
source or binary form and its associated documentation.
|
| 192 |
+
|
| 193 |
+
2. Subject to the terms and conditions of this License Agreement, CNRI
|
| 194 |
+
hereby grants Licensee a nonexclusive, royalty-free, world-wide
|
| 195 |
+
license to reproduce, analyze, test, perform and/or display publicly,
|
| 196 |
+
prepare derivative works, distribute, and otherwise use Python 1.6.1
|
| 197 |
+
alone or in any derivative version, provided, however, that CNRI's
|
| 198 |
+
License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
|
| 199 |
+
1995-2001 Corporation for National Research Initiatives; All Rights
|
| 200 |
+
Reserved" are retained in Python 1.6.1 alone or in any derivative
|
| 201 |
+
version prepared by Licensee. Alternately, in lieu of CNRI's License
|
| 202 |
+
Agreement, Licensee may substitute the following text (omitting the
|
| 203 |
+
quotes): "Python 1.6.1 is made available subject to the terms and
|
| 204 |
+
conditions in CNRI's License Agreement. This Agreement together with
|
| 205 |
+
Python 1.6.1 may be located on the internet using the following
|
| 206 |
+
unique, persistent identifier (known as a handle): 1895.22/1013. This
|
| 207 |
+
Agreement may also be obtained from a proxy server on the internet
|
| 208 |
+
using the following URL: http://hdl.handle.net/1895.22/1013".
|
| 209 |
+
|
| 210 |
+
3. In the event Licensee prepares a derivative work that is based on
|
| 211 |
+
or incorporates Python 1.6.1 or any part thereof, and wants to make
|
| 212 |
+
the derivative work available to others as provided herein, then
|
| 213 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 214 |
+
the changes made to Python 1.6.1.
|
| 215 |
+
|
| 216 |
+
4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
|
| 217 |
+
basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 218 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
|
| 219 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 220 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
|
| 221 |
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
| 222 |
+
|
| 223 |
+
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
| 224 |
+
1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
| 225 |
+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
|
| 226 |
+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
| 227 |
+
|
| 228 |
+
6. This License Agreement will automatically terminate upon a material
|
| 229 |
+
breach of its terms and conditions.
|
| 230 |
+
|
| 231 |
+
7. This License Agreement shall be governed by the federal
|
| 232 |
+
intellectual property law of the United States, including without
|
| 233 |
+
limitation the federal copyright law, and, to the extent such
|
| 234 |
+
U.S. federal law does not apply, by the law of the Commonwealth of
|
| 235 |
+
Virginia, excluding Virginia's conflict of law provisions.
|
| 236 |
+
Notwithstanding the foregoing, with regard to derivative works based
|
| 237 |
+
on Python 1.6.1 that incorporate non-separable material that was
|
| 238 |
+
previously distributed under the GNU General Public License (GPL), the
|
| 239 |
+
law of the Commonwealth of Virginia shall govern this License
|
| 240 |
+
Agreement only as to issues arising under or with respect to
|
| 241 |
+
Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
|
| 242 |
+
License Agreement shall be deemed to create any relationship of
|
| 243 |
+
agency, partnership, or joint venture between CNRI and Licensee. This
|
| 244 |
+
License Agreement does not grant permission to use CNRI trademarks or
|
| 245 |
+
trade name in a trademark sense to endorse or promote products or
|
| 246 |
+
services of Licensee, or any third party.
|
| 247 |
+
|
| 248 |
+
8. By clicking on the "ACCEPT" button where indicated, or by copying,
|
| 249 |
+
installing or otherwise using Python 1.6.1, Licensee agrees to be
|
| 250 |
+
bound by the terms and conditions of this License Agreement.
|
| 251 |
+
|
| 252 |
+
ACCEPT
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
|
| 256 |
+
--------------------------------------------------
|
| 257 |
+
|
| 258 |
+
Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
|
| 259 |
+
The Netherlands. All rights reserved.
|
| 260 |
+
|
| 261 |
+
Permission to use, copy, modify, and distribute this software and its
|
| 262 |
+
documentation for any purpose and without fee is hereby granted,
|
| 263 |
+
provided that the above copyright notice appear in all copies and that
|
| 264 |
+
both that copyright notice and this permission notice appear in
|
| 265 |
+
supporting documentation, and that the name of Stichting Mathematisch
|
| 266 |
+
Centrum or CWI not be used in advertising or publicity pertaining to
|
| 267 |
+
distribution of the software without specific, written prior
|
| 268 |
+
permission.
|
| 269 |
+
|
| 270 |
+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
| 271 |
+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
| 272 |
+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
| 273 |
+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
| 274 |
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
| 275 |
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
| 276 |
+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
| 277 |
+
|
| 278 |
+
ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
|
| 279 |
+
----------------------------------------------------------------------
|
| 280 |
+
|
| 281 |
+
Permission to use, copy, modify, and/or distribute this software for any
|
| 282 |
+
purpose with or without fee is hereby granted.
|
| 283 |
+
|
| 284 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
| 285 |
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
| 286 |
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
| 287 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
| 288 |
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
| 289 |
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
| 290 |
+
PERFORMANCE OF THIS SOFTWARE.
|
testbed/django__django/MANIFEST.in
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
include AUTHORS
|
| 2 |
+
include Gruntfile.js
|
| 3 |
+
include INSTALL
|
| 4 |
+
include LICENSE
|
| 5 |
+
include LICENSE.python
|
| 6 |
+
include MANIFEST.in
|
| 7 |
+
include package.json
|
| 8 |
+
include tox.ini
|
| 9 |
+
include *.rst
|
| 10 |
+
graft django
|
| 11 |
+
graft docs
|
| 12 |
+
graft extras
|
| 13 |
+
graft js_tests
|
| 14 |
+
graft scripts
|
| 15 |
+
graft tests
|
| 16 |
+
global-exclude __pycache__
|
| 17 |
+
global-exclude *.py[co]
|
testbed/django__django/README.rst
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
======
|
| 2 |
+
Django
|
| 3 |
+
======
|
| 4 |
+
|
| 5 |
+
Django is a high-level Python web framework that encourages rapid development
|
| 6 |
+
and clean, pragmatic design. Thanks for checking it out.
|
| 7 |
+
|
| 8 |
+
All documentation is in the "``docs``" directory and online at
|
| 9 |
+
https://docs.djangoproject.com/en/stable/. If you're just getting started,
|
| 10 |
+
here's how we recommend you read the docs:
|
| 11 |
+
|
| 12 |
+
* First, read ``docs/intro/install.txt`` for instructions on installing Django.
|
| 13 |
+
|
| 14 |
+
* Next, work through the tutorials in order (``docs/intro/tutorial01.txt``,
|
| 15 |
+
``docs/intro/tutorial02.txt``, etc.).
|
| 16 |
+
|
| 17 |
+
* If you want to set up an actual deployment server, read
|
| 18 |
+
``docs/howto/deployment/index.txt`` for instructions.
|
| 19 |
+
|
| 20 |
+
* You'll probably want to read through the topical guides (in ``docs/topics``)
|
| 21 |
+
next; from there you can jump to the HOWTOs (in ``docs/howto``) for specific
|
| 22 |
+
problems, and check out the reference (``docs/ref``) for gory details.
|
| 23 |
+
|
| 24 |
+
* See ``docs/README`` for instructions on building an HTML version of the docs.
|
| 25 |
+
|
| 26 |
+
Docs are updated rigorously. If you find any problems in the docs, or think
|
| 27 |
+
they should be clarified in any way, please take 30 seconds to fill out a
|
| 28 |
+
ticket here: https://code.djangoproject.com/newticket
|
| 29 |
+
|
| 30 |
+
To get more help:
|
| 31 |
+
|
| 32 |
+
* Join the ``#django`` channel on ``irc.libera.chat``. Lots of helpful people
|
| 33 |
+
hang out there. `Webchat is available <https://web.libera.chat/#django>`_.
|
| 34 |
+
|
| 35 |
+
* Join the django-users mailing list, or read the archives, at
|
| 36 |
+
https://groups.google.com/group/django-users.
|
| 37 |
+
|
| 38 |
+
* Join the `Django Discord community <https://discord.gg/xcRH6mN4fa>`_.
|
| 39 |
+
|
| 40 |
+
* Join the community on the `Django Forum <https://forum.djangoproject.com/>`_.
|
| 41 |
+
|
| 42 |
+
To contribute to Django:
|
| 43 |
+
|
| 44 |
+
* Check out https://docs.djangoproject.com/en/dev/internals/contributing/ for
|
| 45 |
+
information about getting involved.
|
| 46 |
+
|
| 47 |
+
To run Django's test suite:
|
| 48 |
+
|
| 49 |
+
* Follow the instructions in the "Unit tests" section of
|
| 50 |
+
``docs/internals/contributing/writing-code/unit-tests.txt``, published online at
|
| 51 |
+
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#running-the-unit-tests
|
| 52 |
+
|
| 53 |
+
Supporting the Development of Django
|
| 54 |
+
====================================
|
| 55 |
+
|
| 56 |
+
Django's development depends on your contributions.
|
| 57 |
+
|
| 58 |
+
If you depend on Django, remember to support the Django Software Foundation: https://www.djangoproject.com/fundraising/
|
testbed/django__django/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Django",
|
| 3 |
+
"private": true,
|
| 4 |
+
"scripts": {
|
| 5 |
+
"pretest": "eslint .",
|
| 6 |
+
"test": "grunt test --verbose"
|
| 7 |
+
},
|
| 8 |
+
"engines": {
|
| 9 |
+
"npm": ">=1.3.0"
|
| 10 |
+
},
|
| 11 |
+
"devDependencies": {
|
| 12 |
+
"eslint": "^8.44.0",
|
| 13 |
+
"puppeteer": "^19.11.1",
|
| 14 |
+
"grunt": "^1.6.1",
|
| 15 |
+
"grunt-cli": "^1.4.3",
|
| 16 |
+
"grunt-contrib-qunit": "^7.0.0",
|
| 17 |
+
"qunit": "^2.19.4"
|
| 18 |
+
}
|
| 19 |
+
}
|
testbed/django__django/pyproject.toml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ['setuptools>=40.8.0']
|
| 3 |
+
build-backend = 'setuptools.build_meta'
|
| 4 |
+
|
| 5 |
+
[tool.black]
|
| 6 |
+
target-version = ['py310']
|
| 7 |
+
force-exclude = 'tests/test_runner_apps/tagged/tests_syntax_error.py'
|
testbed/django__django/setup.cfg
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[metadata]
|
| 2 |
+
name = Django
|
| 3 |
+
version = attr: django.__version__
|
| 4 |
+
url = https://www.djangoproject.com/
|
| 5 |
+
author = Django Software Foundation
|
| 6 |
+
author_email = foundation@djangoproject.com
|
| 7 |
+
description = A high-level Python web framework that encourages rapid development and clean, pragmatic design.
|
| 8 |
+
long_description = file: README.rst
|
| 9 |
+
license = BSD-3-Clause
|
| 10 |
+
classifiers =
|
| 11 |
+
Development Status :: 2 - Pre-Alpha
|
| 12 |
+
Environment :: Web Environment
|
| 13 |
+
Framework :: Django
|
| 14 |
+
Intended Audience :: Developers
|
| 15 |
+
License :: OSI Approved :: BSD License
|
| 16 |
+
Operating System :: OS Independent
|
| 17 |
+
Programming Language :: Python
|
| 18 |
+
Programming Language :: Python :: 3
|
| 19 |
+
Programming Language :: Python :: 3 :: Only
|
| 20 |
+
Programming Language :: Python :: 3.10
|
| 21 |
+
Programming Language :: Python :: 3.11
|
| 22 |
+
Topic :: Internet :: WWW/HTTP
|
| 23 |
+
Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 24 |
+
Topic :: Internet :: WWW/HTTP :: WSGI
|
| 25 |
+
Topic :: Software Development :: Libraries :: Application Frameworks
|
| 26 |
+
Topic :: Software Development :: Libraries :: Python Modules
|
| 27 |
+
project_urls =
|
| 28 |
+
Documentation = https://docs.djangoproject.com/
|
| 29 |
+
Release notes = https://docs.djangoproject.com/en/stable/releases/
|
| 30 |
+
Funding = https://www.djangoproject.com/fundraising/
|
| 31 |
+
Source = https://github.com/django/django
|
| 32 |
+
Tracker = https://code.djangoproject.com/
|
| 33 |
+
|
| 34 |
+
[options]
|
| 35 |
+
python_requires = >=3.10
|
| 36 |
+
packages = find:
|
| 37 |
+
include_package_data = true
|
| 38 |
+
zip_safe = false
|
| 39 |
+
install_requires =
|
| 40 |
+
asgiref >= 3.7.0
|
| 41 |
+
sqlparse >= 0.3.1
|
| 42 |
+
tzdata; sys_platform == 'win32'
|
| 43 |
+
|
| 44 |
+
[options.entry_points]
|
| 45 |
+
console_scripts =
|
| 46 |
+
django-admin = django.core.management:execute_from_command_line
|
| 47 |
+
|
| 48 |
+
[options.extras_require]
|
| 49 |
+
argon2 = argon2-cffi >= 19.1.0
|
| 50 |
+
bcrypt = bcrypt
|
| 51 |
+
|
| 52 |
+
[bdist_rpm]
|
| 53 |
+
doc_files = docs extras AUTHORS INSTALL LICENSE README.rst
|
| 54 |
+
install_script = scripts/rpm-install.sh
|
| 55 |
+
|
| 56 |
+
[flake8]
|
| 57 |
+
exclude = build,.git,.tox,./tests/.env
|
| 58 |
+
extend-ignore = E203
|
| 59 |
+
max-line-length = 88
|
| 60 |
+
per-file-ignores =
|
| 61 |
+
django/core/cache/backends/filebased.py:W601
|
| 62 |
+
django/core/cache/backends/base.py:W601
|
| 63 |
+
django/core/cache/backends/redis.py:W601
|
| 64 |
+
tests/cache/tests.py:W601
|
| 65 |
+
|
| 66 |
+
[isort]
|
| 67 |
+
profile = black
|
| 68 |
+
default_section = THIRDPARTY
|
| 69 |
+
known_first_party = django
|
testbed/django__django/setup.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import site
|
| 3 |
+
import sys
|
| 4 |
+
from distutils.sysconfig import get_python_lib
|
| 5 |
+
|
| 6 |
+
from setuptools import setup
|
| 7 |
+
|
| 8 |
+
# Allow editable install into user site directory.
|
| 9 |
+
# See https://github.com/pypa/pip/issues/7953.
|
| 10 |
+
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]
|
| 11 |
+
|
| 12 |
+
# Warn if we are installing over top of an existing installation. This can
|
| 13 |
+
# cause issues where files that were deleted from a more recent Django are
|
| 14 |
+
# still present in site-packages. See #18115.
|
| 15 |
+
overlay_warning = False
|
| 16 |
+
if "install" in sys.argv:
|
| 17 |
+
lib_paths = [get_python_lib()]
|
| 18 |
+
if lib_paths[0].startswith("/usr/lib/"):
|
| 19 |
+
# We have to try also with an explicit prefix of /usr/local in order to
|
| 20 |
+
# catch Debian's custom user site-packages directory.
|
| 21 |
+
lib_paths.append(get_python_lib(prefix="/usr/local"))
|
| 22 |
+
for lib_path in lib_paths:
|
| 23 |
+
existing_path = os.path.abspath(os.path.join(lib_path, "django"))
|
| 24 |
+
if os.path.exists(existing_path):
|
| 25 |
+
# We note the need for the warning here, but present it after the
|
| 26 |
+
# command is run, so it's more likely to be seen.
|
| 27 |
+
overlay_warning = True
|
| 28 |
+
break
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
setup()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if overlay_warning:
|
| 35 |
+
sys.stderr.write(
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
========
|
| 39 |
+
WARNING!
|
| 40 |
+
========
|
| 41 |
+
|
| 42 |
+
You have just installed Django over top of an existing
|
| 43 |
+
installation, without removing it first. Because of this,
|
| 44 |
+
your install may now include extraneous files from a
|
| 45 |
+
previous version that have since been removed from
|
| 46 |
+
Django. This is known to cause a variety of problems. You
|
| 47 |
+
should manually remove the
|
| 48 |
+
|
| 49 |
+
%(existing_path)s
|
| 50 |
+
|
| 51 |
+
directory and re-install Django.
|
| 52 |
+
|
| 53 |
+
"""
|
| 54 |
+
% {"existing_path": existing_path}
|
| 55 |
+
)
|
testbed/django__django/tests/.coveragerc
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[run]
|
| 2 |
+
branch = True
|
| 3 |
+
concurrency = multiprocessing,thread
|
| 4 |
+
data_file = .coverages/.coverage
|
| 5 |
+
omit =
|
| 6 |
+
*/django/utils/autoreload.py
|
| 7 |
+
source = django
|
| 8 |
+
|
| 9 |
+
[report]
|
| 10 |
+
ignore_errors = True
|
| 11 |
+
omit =
|
| 12 |
+
*/django/conf/locale/*
|
| 13 |
+
*/tests/*
|
| 14 |
+
|
| 15 |
+
[html]
|
| 16 |
+
directory = coverage_html
|
testbed/django__django/tests/README.rst
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
To run the test suite, first, create and activate a virtual environment. Then
|
| 2 |
+
install some requirements and run the tests::
|
| 3 |
+
|
| 4 |
+
$ cd tests
|
| 5 |
+
$ python -m pip install -e ..
|
| 6 |
+
$ python -m pip install -r requirements/py3.txt
|
| 7 |
+
$ ./runtests.py
|
| 8 |
+
|
| 9 |
+
For more information about the test suite, see
|
| 10 |
+
https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/.
|
testbed/django__django/tests/model_fields/test_field_flags.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django import test
|
| 2 |
+
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
| 3 |
+
from django.db import models
|
| 4 |
+
|
| 5 |
+
from .models import AllFieldsModel
|
| 6 |
+
|
| 7 |
+
NON_CONCRETE_FIELDS = (
|
| 8 |
+
models.ForeignObject,
|
| 9 |
+
GenericForeignKey,
|
| 10 |
+
GenericRelation,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
NON_EDITABLE_FIELDS = (
|
| 14 |
+
models.BinaryField,
|
| 15 |
+
GenericForeignKey,
|
| 16 |
+
GenericRelation,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
RELATION_FIELDS = (
|
| 20 |
+
models.ForeignKey,
|
| 21 |
+
models.ForeignObject,
|
| 22 |
+
models.ManyToManyField,
|
| 23 |
+
models.OneToOneField,
|
| 24 |
+
GenericForeignKey,
|
| 25 |
+
GenericRelation,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
MANY_TO_MANY_CLASSES = {
|
| 29 |
+
models.ManyToManyField,
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
MANY_TO_ONE_CLASSES = {
|
| 33 |
+
models.ForeignObject,
|
| 34 |
+
models.ForeignKey,
|
| 35 |
+
GenericForeignKey,
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
ONE_TO_MANY_CLASSES = {
|
| 39 |
+
models.ForeignObjectRel,
|
| 40 |
+
models.ManyToOneRel,
|
| 41 |
+
GenericRelation,
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
ONE_TO_ONE_CLASSES = {
|
| 45 |
+
models.OneToOneField,
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
FLAG_PROPERTIES = (
|
| 49 |
+
"concrete",
|
| 50 |
+
"editable",
|
| 51 |
+
"is_relation",
|
| 52 |
+
"model",
|
| 53 |
+
"hidden",
|
| 54 |
+
"one_to_many",
|
| 55 |
+
"many_to_one",
|
| 56 |
+
"many_to_many",
|
| 57 |
+
"one_to_one",
|
| 58 |
+
"related_model",
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
FLAG_PROPERTIES_FOR_RELATIONS = (
|
| 62 |
+
"one_to_many",
|
| 63 |
+
"many_to_one",
|
| 64 |
+
"many_to_many",
|
| 65 |
+
"one_to_one",
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class FieldFlagsTests(test.SimpleTestCase):
|
| 70 |
+
@classmethod
|
| 71 |
+
def setUpClass(cls):
|
| 72 |
+
super().setUpClass()
|
| 73 |
+
cls.fields = [
|
| 74 |
+
*AllFieldsModel._meta.fields,
|
| 75 |
+
*AllFieldsModel._meta.private_fields,
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
cls.all_fields = [
|
| 79 |
+
*cls.fields,
|
| 80 |
+
*AllFieldsModel._meta.many_to_many,
|
| 81 |
+
*AllFieldsModel._meta.private_fields,
|
| 82 |
+
]
|
| 83 |
+
|
| 84 |
+
cls.fields_and_reverse_objects = [
|
| 85 |
+
*cls.all_fields,
|
| 86 |
+
*AllFieldsModel._meta.related_objects,
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
def test_each_field_should_have_a_concrete_attribute(self):
|
| 90 |
+
self.assertTrue(all(f.concrete.__class__ == bool for f in self.fields))
|
| 91 |
+
|
| 92 |
+
def test_each_field_should_have_an_editable_attribute(self):
|
| 93 |
+
self.assertTrue(all(f.editable.__class__ == bool for f in self.all_fields))
|
| 94 |
+
|
| 95 |
+
def test_each_field_should_have_a_has_rel_attribute(self):
|
| 96 |
+
self.assertTrue(all(f.is_relation.__class__ == bool for f in self.all_fields))
|
| 97 |
+
|
| 98 |
+
def test_each_object_should_have_auto_created(self):
|
| 99 |
+
self.assertTrue(
|
| 100 |
+
all(
|
| 101 |
+
f.auto_created.__class__ == bool
|
| 102 |
+
for f in self.fields_and_reverse_objects
|
| 103 |
+
)
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
def test_non_concrete_fields(self):
|
| 107 |
+
for field in self.fields:
|
| 108 |
+
if type(field) in NON_CONCRETE_FIELDS:
|
| 109 |
+
self.assertFalse(field.concrete)
|
| 110 |
+
else:
|
| 111 |
+
self.assertTrue(field.concrete)
|
| 112 |
+
|
| 113 |
+
def test_non_editable_fields(self):
|
| 114 |
+
for field in self.all_fields:
|
| 115 |
+
if type(field) in NON_EDITABLE_FIELDS:
|
| 116 |
+
self.assertFalse(field.editable)
|
| 117 |
+
else:
|
| 118 |
+
self.assertTrue(field.editable)
|
| 119 |
+
|
| 120 |
+
def test_related_fields(self):
|
| 121 |
+
for field in self.all_fields:
|
| 122 |
+
if type(field) in RELATION_FIELDS:
|
| 123 |
+
self.assertTrue(field.is_relation)
|
| 124 |
+
else:
|
| 125 |
+
self.assertFalse(field.is_relation)
|
| 126 |
+
|
| 127 |
+
def test_field_names_should_always_be_available(self):
|
| 128 |
+
for field in self.fields_and_reverse_objects:
|
| 129 |
+
self.assertTrue(field.name)
|
| 130 |
+
|
| 131 |
+
def test_all_field_types_should_have_flags(self):
|
| 132 |
+
for field in self.fields_and_reverse_objects:
|
| 133 |
+
for flag in FLAG_PROPERTIES:
|
| 134 |
+
self.assertTrue(
|
| 135 |
+
hasattr(field, flag),
|
| 136 |
+
"Field %s does not have flag %s" % (field, flag),
|
| 137 |
+
)
|
| 138 |
+
if field.is_relation:
|
| 139 |
+
true_cardinality_flags = sum(
|
| 140 |
+
getattr(field, flag) is True
|
| 141 |
+
for flag in FLAG_PROPERTIES_FOR_RELATIONS
|
| 142 |
+
)
|
| 143 |
+
# If the field has a relation, there should be only one of the
|
| 144 |
+
# 4 cardinality flags available.
|
| 145 |
+
self.assertEqual(1, true_cardinality_flags)
|
| 146 |
+
|
| 147 |
+
def test_cardinality_m2m(self):
|
| 148 |
+
m2m_type_fields = [
|
| 149 |
+
f for f in self.all_fields if f.is_relation and f.many_to_many
|
| 150 |
+
]
|
| 151 |
+
# Test classes are what we expect
|
| 152 |
+
self.assertEqual(MANY_TO_MANY_CLASSES, {f.__class__ for f in m2m_type_fields})
|
| 153 |
+
|
| 154 |
+
# Ensure all m2m reverses are m2m
|
| 155 |
+
for field in m2m_type_fields:
|
| 156 |
+
reverse_field = field.remote_field
|
| 157 |
+
self.assertTrue(reverse_field.is_relation)
|
| 158 |
+
self.assertTrue(reverse_field.many_to_many)
|
| 159 |
+
self.assertTrue(reverse_field.related_model)
|
| 160 |
+
|
| 161 |
+
def test_cardinality_o2m(self):
|
| 162 |
+
o2m_type_fields = [
|
| 163 |
+
f
|
| 164 |
+
for f in self.fields_and_reverse_objects
|
| 165 |
+
if f.is_relation and f.one_to_many
|
| 166 |
+
]
|
| 167 |
+
# Test classes are what we expect
|
| 168 |
+
self.assertEqual(ONE_TO_MANY_CLASSES, {f.__class__ for f in o2m_type_fields})
|
| 169 |
+
|
| 170 |
+
# Ensure all o2m reverses are m2o
|
| 171 |
+
for field in o2m_type_fields:
|
| 172 |
+
if field.concrete:
|
| 173 |
+
reverse_field = field.remote_field
|
| 174 |
+
self.assertTrue(reverse_field.is_relation and reverse_field.many_to_one)
|
| 175 |
+
|
| 176 |
+
def test_cardinality_m2o(self):
|
| 177 |
+
m2o_type_fields = [
|
| 178 |
+
f
|
| 179 |
+
for f in self.fields_and_reverse_objects
|
| 180 |
+
if f.is_relation and f.many_to_one
|
| 181 |
+
]
|
| 182 |
+
# Test classes are what we expect
|
| 183 |
+
self.assertEqual(MANY_TO_ONE_CLASSES, {f.__class__ for f in m2o_type_fields})
|
| 184 |
+
|
| 185 |
+
# Ensure all m2o reverses are o2m
|
| 186 |
+
for obj in m2o_type_fields:
|
| 187 |
+
if hasattr(obj, "field"):
|
| 188 |
+
reverse_field = obj.field
|
| 189 |
+
self.assertTrue(reverse_field.is_relation and reverse_field.one_to_many)
|
| 190 |
+
|
| 191 |
+
def test_cardinality_o2o(self):
|
| 192 |
+
o2o_type_fields = [f for f in self.all_fields if f.is_relation and f.one_to_one]
|
| 193 |
+
# Test classes are what we expect
|
| 194 |
+
self.assertEqual(ONE_TO_ONE_CLASSES, {f.__class__ for f in o2o_type_fields})
|
| 195 |
+
|
| 196 |
+
# Ensure all o2o reverses are o2o
|
| 197 |
+
for obj in o2o_type_fields:
|
| 198 |
+
if hasattr(obj, "field"):
|
| 199 |
+
reverse_field = obj.field
|
| 200 |
+
self.assertTrue(reverse_field.is_relation and reverse_field.one_to_one)
|
| 201 |
+
|
| 202 |
+
def test_hidden_flag(self):
|
| 203 |
+
incl_hidden = set(AllFieldsModel._meta.get_fields(include_hidden=True))
|
| 204 |
+
no_hidden = set(AllFieldsModel._meta.get_fields())
|
| 205 |
+
fields_that_should_be_hidden = incl_hidden - no_hidden
|
| 206 |
+
for f in incl_hidden:
|
| 207 |
+
self.assertEqual(f in fields_that_should_be_hidden, f.hidden)
|
| 208 |
+
|
| 209 |
+
def test_model_and_reverse_model_should_equal_on_relations(self):
|
| 210 |
+
for field in AllFieldsModel._meta.get_fields():
|
| 211 |
+
is_concrete_forward_field = field.concrete and field.related_model
|
| 212 |
+
if is_concrete_forward_field:
|
| 213 |
+
reverse_field = field.remote_field
|
| 214 |
+
self.assertEqual(field.model, reverse_field.related_model)
|
| 215 |
+
self.assertEqual(field.related_model, reverse_field.model)
|
| 216 |
+
|
| 217 |
+
def test_null(self):
|
| 218 |
+
# null isn't well defined for a ManyToManyField, but changing it to
|
| 219 |
+
# True causes backwards compatibility problems (#25320).
|
| 220 |
+
self.assertFalse(AllFieldsModel._meta.get_field("m2m").null)
|
| 221 |
+
self.assertTrue(AllFieldsModel._meta.get_field("reverse2").null)
|
testbed/django__django/tests/model_fields/test_filepathfield.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
from django.db.models import FilePathField
|
| 4 |
+
from django.test import SimpleTestCase
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class FilePathFieldTests(SimpleTestCase):
|
| 8 |
+
def test_path(self):
|
| 9 |
+
path = os.path.dirname(__file__)
|
| 10 |
+
field = FilePathField(path=path)
|
| 11 |
+
self.assertEqual(field.path, path)
|
| 12 |
+
self.assertEqual(field.formfield().path, path)
|
| 13 |
+
|
| 14 |
+
def test_callable_path(self):
|
| 15 |
+
path = os.path.dirname(__file__)
|
| 16 |
+
|
| 17 |
+
def generate_path():
|
| 18 |
+
return path
|
| 19 |
+
|
| 20 |
+
field = FilePathField(path=generate_path)
|
| 21 |
+
self.assertEqual(field.path(), path)
|
| 22 |
+
self.assertEqual(field.formfield().path, path)
|
testbed/django__django/tests/model_fields/test_foreignkey.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from decimal import Decimal
|
| 2 |
+
|
| 3 |
+
from django.apps import apps
|
| 4 |
+
from django.core import checks
|
| 5 |
+
from django.core.exceptions import FieldError
|
| 6 |
+
from django.db import models
|
| 7 |
+
from django.test import TestCase, skipIfDBFeature
|
| 8 |
+
from django.test.utils import isolate_apps
|
| 9 |
+
|
| 10 |
+
from .models import Bar, FkToChar, Foo, PrimaryKeyCharModel
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class ForeignKeyTests(TestCase):
|
| 14 |
+
def test_callable_default(self):
|
| 15 |
+
"""A lazy callable may be used for ForeignKey.default."""
|
| 16 |
+
a = Foo.objects.create(id=1, a="abc", d=Decimal("12.34"))
|
| 17 |
+
b = Bar.objects.create(b="bcd")
|
| 18 |
+
self.assertEqual(b.a, a)
|
| 19 |
+
|
| 20 |
+
@skipIfDBFeature("interprets_empty_strings_as_nulls")
|
| 21 |
+
def test_empty_string_fk(self):
|
| 22 |
+
"""
|
| 23 |
+
Empty strings foreign key values don't get converted to None (#19299).
|
| 24 |
+
"""
|
| 25 |
+
char_model_empty = PrimaryKeyCharModel.objects.create(string="")
|
| 26 |
+
fk_model_empty = FkToChar.objects.create(out=char_model_empty)
|
| 27 |
+
fk_model_empty = FkToChar.objects.select_related("out").get(
|
| 28 |
+
id=fk_model_empty.pk
|
| 29 |
+
)
|
| 30 |
+
self.assertEqual(fk_model_empty.out, char_model_empty)
|
| 31 |
+
|
| 32 |
+
@isolate_apps("model_fields")
|
| 33 |
+
def test_warning_when_unique_true_on_fk(self):
|
| 34 |
+
class Foo(models.Model):
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
class FKUniqueTrue(models.Model):
|
| 38 |
+
fk_field = models.ForeignKey(Foo, models.CASCADE, unique=True)
|
| 39 |
+
|
| 40 |
+
model = FKUniqueTrue()
|
| 41 |
+
expected_warnings = [
|
| 42 |
+
checks.Warning(
|
| 43 |
+
"Setting unique=True on a ForeignKey has the same effect as using a "
|
| 44 |
+
"OneToOneField.",
|
| 45 |
+
hint=(
|
| 46 |
+
"ForeignKey(unique=True) is usually better served by a "
|
| 47 |
+
"OneToOneField."
|
| 48 |
+
),
|
| 49 |
+
obj=FKUniqueTrue.fk_field.field,
|
| 50 |
+
id="fields.W342",
|
| 51 |
+
)
|
| 52 |
+
]
|
| 53 |
+
warnings = model.check()
|
| 54 |
+
self.assertEqual(warnings, expected_warnings)
|
| 55 |
+
|
| 56 |
+
def test_related_name_converted_to_text(self):
|
| 57 |
+
rel_name = Bar._meta.get_field("a").remote_field.related_name
|
| 58 |
+
self.assertIsInstance(rel_name, str)
|
| 59 |
+
|
| 60 |
+
def test_abstract_model_pending_operations(self):
|
| 61 |
+
"""
|
| 62 |
+
Foreign key fields declared on abstract models should not add lazy
|
| 63 |
+
relations to resolve relationship declared as string (#24215).
|
| 64 |
+
"""
|
| 65 |
+
pending_ops_before = list(apps._pending_operations.items())
|
| 66 |
+
|
| 67 |
+
class AbstractForeignKeyModel(models.Model):
|
| 68 |
+
fk = models.ForeignKey("missing.FK", models.CASCADE)
|
| 69 |
+
|
| 70 |
+
class Meta:
|
| 71 |
+
abstract = True
|
| 72 |
+
|
| 73 |
+
self.assertIs(AbstractForeignKeyModel._meta.apps, apps)
|
| 74 |
+
self.assertEqual(
|
| 75 |
+
pending_ops_before,
|
| 76 |
+
list(apps._pending_operations.items()),
|
| 77 |
+
"Pending lookup added for a foreign key on an abstract model",
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
@isolate_apps("model_fields", "model_fields.tests")
|
| 81 |
+
def test_abstract_model_app_relative_foreign_key(self):
|
| 82 |
+
class AbstractReferent(models.Model):
|
| 83 |
+
reference = models.ForeignKey("Referred", on_delete=models.CASCADE)
|
| 84 |
+
|
| 85 |
+
class Meta:
|
| 86 |
+
app_label = "model_fields"
|
| 87 |
+
abstract = True
|
| 88 |
+
|
| 89 |
+
def assert_app_model_resolved(label):
|
| 90 |
+
class Referred(models.Model):
|
| 91 |
+
class Meta:
|
| 92 |
+
app_label = label
|
| 93 |
+
|
| 94 |
+
class ConcreteReferent(AbstractReferent):
|
| 95 |
+
class Meta:
|
| 96 |
+
app_label = label
|
| 97 |
+
|
| 98 |
+
self.assertEqual(
|
| 99 |
+
ConcreteReferent._meta.get_field("reference").related_model, Referred
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
assert_app_model_resolved("model_fields")
|
| 103 |
+
assert_app_model_resolved("tests")
|
| 104 |
+
|
| 105 |
+
@isolate_apps("model_fields")
|
| 106 |
+
def test_to_python(self):
|
| 107 |
+
class Foo(models.Model):
|
| 108 |
+
pass
|
| 109 |
+
|
| 110 |
+
class Bar(models.Model):
|
| 111 |
+
fk = models.ForeignKey(Foo, models.CASCADE)
|
| 112 |
+
|
| 113 |
+
self.assertEqual(Bar._meta.get_field("fk").to_python("1"), 1)
|
| 114 |
+
|
| 115 |
+
@isolate_apps("model_fields")
|
| 116 |
+
def test_fk_to_fk_get_col_output_field(self):
|
| 117 |
+
class Foo(models.Model):
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
class Bar(models.Model):
|
| 121 |
+
foo = models.ForeignKey(Foo, models.CASCADE, primary_key=True)
|
| 122 |
+
|
| 123 |
+
class Baz(models.Model):
|
| 124 |
+
bar = models.ForeignKey(Bar, models.CASCADE, primary_key=True)
|
| 125 |
+
|
| 126 |
+
col = Baz._meta.get_field("bar").get_col("alias")
|
| 127 |
+
self.assertIs(col.output_field, Foo._meta.pk)
|
| 128 |
+
|
| 129 |
+
@isolate_apps("model_fields")
|
| 130 |
+
def test_recursive_fks_get_col(self):
|
| 131 |
+
class Foo(models.Model):
|
| 132 |
+
bar = models.ForeignKey("Bar", models.CASCADE, primary_key=True)
|
| 133 |
+
|
| 134 |
+
class Bar(models.Model):
|
| 135 |
+
foo = models.ForeignKey(Foo, models.CASCADE, primary_key=True)
|
| 136 |
+
|
| 137 |
+
with self.assertRaisesMessage(ValueError, "Cannot resolve output_field"):
|
| 138 |
+
Foo._meta.get_field("bar").get_col("alias")
|
| 139 |
+
|
| 140 |
+
@isolate_apps("model_fields")
|
| 141 |
+
def test_non_local_to_field(self):
|
| 142 |
+
class Parent(models.Model):
|
| 143 |
+
key = models.IntegerField(unique=True)
|
| 144 |
+
|
| 145 |
+
class Child(Parent):
|
| 146 |
+
pass
|
| 147 |
+
|
| 148 |
+
class Related(models.Model):
|
| 149 |
+
child = models.ForeignKey(Child, on_delete=models.CASCADE, to_field="key")
|
| 150 |
+
|
| 151 |
+
msg = (
|
| 152 |
+
"'model_fields.Related.child' refers to field 'key' which is not "
|
| 153 |
+
"local to model 'model_fields.Child'."
|
| 154 |
+
)
|
| 155 |
+
with self.assertRaisesMessage(FieldError, msg):
|
| 156 |
+
Related._meta.get_field("child").related_fields
|
| 157 |
+
|
| 158 |
+
def test_invalid_to_parameter(self):
|
| 159 |
+
msg = (
|
| 160 |
+
"ForeignKey(1) is invalid. First parameter to ForeignKey must be "
|
| 161 |
+
"either a model, a model name, or the string 'self'"
|
| 162 |
+
)
|
| 163 |
+
with self.assertRaisesMessage(TypeError, msg):
|
| 164 |
+
|
| 165 |
+
class MyModel(models.Model):
|
| 166 |
+
child = models.ForeignKey(1, models.CASCADE)
|
| 167 |
+
|
| 168 |
+
def test_manager_class_getitem(self):
|
| 169 |
+
self.assertIs(models.ForeignKey["Foo"], models.ForeignKey)
|
testbed/django__django/tests/model_fields/test_jsonfield.py
ADDED
|
@@ -0,0 +1,1144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 5 |
+
from django import forms
|
| 6 |
+
from django.core import serializers
|
| 7 |
+
from django.core.exceptions import ValidationError
|
| 8 |
+
from django.core.serializers.json import DjangoJSONEncoder
|
| 9 |
+
from django.db import (
|
| 10 |
+
DataError,
|
| 11 |
+
IntegrityError,
|
| 12 |
+
NotSupportedError,
|
| 13 |
+
OperationalError,
|
| 14 |
+
connection,
|
| 15 |
+
models,
|
| 16 |
+
)
|
| 17 |
+
from django.db.models import (
|
| 18 |
+
Count,
|
| 19 |
+
ExpressionWrapper,
|
| 20 |
+
F,
|
| 21 |
+
IntegerField,
|
| 22 |
+
JSONField,
|
| 23 |
+
OuterRef,
|
| 24 |
+
Q,
|
| 25 |
+
Subquery,
|
| 26 |
+
Transform,
|
| 27 |
+
Value,
|
| 28 |
+
)
|
| 29 |
+
from django.db.models.expressions import RawSQL
|
| 30 |
+
from django.db.models.fields.json import (
|
| 31 |
+
KT,
|
| 32 |
+
KeyTextTransform,
|
| 33 |
+
KeyTransform,
|
| 34 |
+
KeyTransformFactory,
|
| 35 |
+
KeyTransformTextLookupMixin,
|
| 36 |
+
)
|
| 37 |
+
from django.db.models.functions import Cast
|
| 38 |
+
from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature
|
| 39 |
+
from django.test.utils import CaptureQueriesContext
|
| 40 |
+
from django.utils.deprecation import RemovedInDjango51Warning
|
| 41 |
+
|
| 42 |
+
from .models import CustomJSONDecoder, JSONModel, NullableJSONModel, RelatedJSONModel
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@skipUnlessDBFeature("supports_json_field")
|
| 46 |
+
class JSONFieldTests(TestCase):
|
| 47 |
+
def test_invalid_value(self):
|
| 48 |
+
msg = "is not JSON serializable"
|
| 49 |
+
with self.assertRaisesMessage(TypeError, msg):
|
| 50 |
+
NullableJSONModel.objects.create(
|
| 51 |
+
value={
|
| 52 |
+
"uuid": uuid.UUID("d85e2076-b67c-4ee7-8c3a-2bf5a2cc2475"),
|
| 53 |
+
}
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
def test_custom_encoder_decoder(self):
|
| 57 |
+
value = {"uuid": uuid.UUID("{d85e2076-b67c-4ee7-8c3a-2bf5a2cc2475}")}
|
| 58 |
+
obj = NullableJSONModel(value_custom=value)
|
| 59 |
+
obj.clean_fields()
|
| 60 |
+
obj.save()
|
| 61 |
+
obj.refresh_from_db()
|
| 62 |
+
self.assertEqual(obj.value_custom, value)
|
| 63 |
+
|
| 64 |
+
def test_db_check_constraints(self):
|
| 65 |
+
value = "{@!invalid json value 123 $!@#"
|
| 66 |
+
with mock.patch.object(DjangoJSONEncoder, "encode", return_value=value):
|
| 67 |
+
with self.assertRaises((IntegrityError, DataError, OperationalError)):
|
| 68 |
+
NullableJSONModel.objects.create(value_custom=value)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class TestMethods(SimpleTestCase):
|
| 72 |
+
def test_deconstruct(self):
|
| 73 |
+
field = models.JSONField()
|
| 74 |
+
name, path, args, kwargs = field.deconstruct()
|
| 75 |
+
self.assertEqual(path, "django.db.models.JSONField")
|
| 76 |
+
self.assertEqual(args, [])
|
| 77 |
+
self.assertEqual(kwargs, {})
|
| 78 |
+
|
| 79 |
+
def test_deconstruct_custom_encoder_decoder(self):
|
| 80 |
+
field = models.JSONField(encoder=DjangoJSONEncoder, decoder=CustomJSONDecoder)
|
| 81 |
+
name, path, args, kwargs = field.deconstruct()
|
| 82 |
+
self.assertEqual(kwargs["encoder"], DjangoJSONEncoder)
|
| 83 |
+
self.assertEqual(kwargs["decoder"], CustomJSONDecoder)
|
| 84 |
+
|
| 85 |
+
def test_get_transforms(self):
|
| 86 |
+
@models.JSONField.register_lookup
|
| 87 |
+
class MyTransform(Transform):
|
| 88 |
+
lookup_name = "my_transform"
|
| 89 |
+
|
| 90 |
+
field = models.JSONField()
|
| 91 |
+
transform = field.get_transform("my_transform")
|
| 92 |
+
self.assertIs(transform, MyTransform)
|
| 93 |
+
models.JSONField._unregister_lookup(MyTransform)
|
| 94 |
+
transform = field.get_transform("my_transform")
|
| 95 |
+
self.assertIsInstance(transform, KeyTransformFactory)
|
| 96 |
+
|
| 97 |
+
def test_key_transform_text_lookup_mixin_non_key_transform(self):
|
| 98 |
+
transform = Transform("test")
|
| 99 |
+
msg = (
|
| 100 |
+
"Transform should be an instance of KeyTransform in order to use "
|
| 101 |
+
"this lookup."
|
| 102 |
+
)
|
| 103 |
+
with self.assertRaisesMessage(TypeError, msg):
|
| 104 |
+
KeyTransformTextLookupMixin(transform)
|
| 105 |
+
|
| 106 |
+
def test_get_prep_value(self):
|
| 107 |
+
class JSONFieldGetPrepValue(models.JSONField):
|
| 108 |
+
def get_prep_value(self, value):
|
| 109 |
+
if value is True:
|
| 110 |
+
return {"value": True}
|
| 111 |
+
return value
|
| 112 |
+
|
| 113 |
+
def noop_adapt_json_value(value, encoder):
|
| 114 |
+
return value
|
| 115 |
+
|
| 116 |
+
field = JSONFieldGetPrepValue()
|
| 117 |
+
with mock.patch.object(
|
| 118 |
+
connection.ops, "adapt_json_value", noop_adapt_json_value
|
| 119 |
+
):
|
| 120 |
+
self.assertEqual(
|
| 121 |
+
field.get_db_prep_value(True, connection, prepared=False),
|
| 122 |
+
{"value": True},
|
| 123 |
+
)
|
| 124 |
+
self.assertIs(
|
| 125 |
+
field.get_db_prep_value(True, connection, prepared=True), True
|
| 126 |
+
)
|
| 127 |
+
self.assertEqual(field.get_db_prep_value(1, connection, prepared=False), 1)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
class TestValidation(SimpleTestCase):
|
| 131 |
+
def test_invalid_encoder(self):
|
| 132 |
+
msg = "The encoder parameter must be a callable object."
|
| 133 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 134 |
+
models.JSONField(encoder=DjangoJSONEncoder())
|
| 135 |
+
|
| 136 |
+
def test_invalid_decoder(self):
|
| 137 |
+
msg = "The decoder parameter must be a callable object."
|
| 138 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 139 |
+
models.JSONField(decoder=CustomJSONDecoder())
|
| 140 |
+
|
| 141 |
+
def test_validation_error(self):
|
| 142 |
+
field = models.JSONField()
|
| 143 |
+
msg = "Value must be valid JSON."
|
| 144 |
+
value = uuid.UUID("{d85e2076-b67c-4ee7-8c3a-2bf5a2cc2475}")
|
| 145 |
+
with self.assertRaisesMessage(ValidationError, msg):
|
| 146 |
+
field.clean({"uuid": value}, None)
|
| 147 |
+
|
| 148 |
+
def test_custom_encoder(self):
|
| 149 |
+
field = models.JSONField(encoder=DjangoJSONEncoder)
|
| 150 |
+
value = uuid.UUID("{d85e2076-b67c-4ee7-8c3a-2bf5a2cc2475}")
|
| 151 |
+
field.clean({"uuid": value}, None)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class TestFormField(SimpleTestCase):
|
| 155 |
+
def test_formfield(self):
|
| 156 |
+
model_field = models.JSONField()
|
| 157 |
+
form_field = model_field.formfield()
|
| 158 |
+
self.assertIsInstance(form_field, forms.JSONField)
|
| 159 |
+
|
| 160 |
+
def test_formfield_custom_encoder_decoder(self):
|
| 161 |
+
model_field = models.JSONField(
|
| 162 |
+
encoder=DjangoJSONEncoder, decoder=CustomJSONDecoder
|
| 163 |
+
)
|
| 164 |
+
form_field = model_field.formfield()
|
| 165 |
+
self.assertIs(form_field.encoder, DjangoJSONEncoder)
|
| 166 |
+
self.assertIs(form_field.decoder, CustomJSONDecoder)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class TestSerialization(SimpleTestCase):
|
| 170 |
+
test_data = (
|
| 171 |
+
'[{"fields": {"value": %s}, "model": "model_fields.jsonmodel", "pk": null}]'
|
| 172 |
+
)
|
| 173 |
+
test_values = (
|
| 174 |
+
# (Python value, serialized value),
|
| 175 |
+
({"a": "b", "c": None}, '{"a": "b", "c": null}'),
|
| 176 |
+
("abc", '"abc"'),
|
| 177 |
+
('{"a": "a"}', '"{\\"a\\": \\"a\\"}"'),
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
def test_dumping(self):
|
| 181 |
+
for value, serialized in self.test_values:
|
| 182 |
+
with self.subTest(value=value):
|
| 183 |
+
instance = JSONModel(value=value)
|
| 184 |
+
data = serializers.serialize("json", [instance])
|
| 185 |
+
self.assertJSONEqual(data, self.test_data % serialized)
|
| 186 |
+
|
| 187 |
+
def test_loading(self):
|
| 188 |
+
for value, serialized in self.test_values:
|
| 189 |
+
with self.subTest(value=value):
|
| 190 |
+
instance = list(
|
| 191 |
+
serializers.deserialize("json", self.test_data % serialized)
|
| 192 |
+
)[0].object
|
| 193 |
+
self.assertEqual(instance.value, value)
|
| 194 |
+
|
| 195 |
+
def test_xml_serialization(self):
|
| 196 |
+
test_xml_data = (
|
| 197 |
+
'<django-objects version="1.0">'
|
| 198 |
+
'<object model="model_fields.nullablejsonmodel">'
|
| 199 |
+
'<field name="value" type="JSONField">%s'
|
| 200 |
+
"</field></object></django-objects>"
|
| 201 |
+
)
|
| 202 |
+
for value, serialized in self.test_values:
|
| 203 |
+
with self.subTest(value=value):
|
| 204 |
+
instance = NullableJSONModel(value=value)
|
| 205 |
+
data = serializers.serialize("xml", [instance], fields=["value"])
|
| 206 |
+
self.assertXMLEqual(data, test_xml_data % serialized)
|
| 207 |
+
new_instance = list(serializers.deserialize("xml", data))[0].object
|
| 208 |
+
self.assertEqual(new_instance.value, instance.value)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
@skipUnlessDBFeature("supports_json_field")
|
| 212 |
+
class TestSaveLoad(TestCase):
|
| 213 |
+
def test_null(self):
|
| 214 |
+
obj = NullableJSONModel(value=None)
|
| 215 |
+
obj.save()
|
| 216 |
+
obj.refresh_from_db()
|
| 217 |
+
self.assertIsNone(obj.value)
|
| 218 |
+
|
| 219 |
+
def test_ambiguous_str_value_deprecation(self):
|
| 220 |
+
msg = (
|
| 221 |
+
"Providing an encoded JSON string via Value() is deprecated. Use Value([], "
|
| 222 |
+
"output_field=JSONField()) instead."
|
| 223 |
+
)
|
| 224 |
+
with self.assertWarnsMessage(RemovedInDjango51Warning, msg):
|
| 225 |
+
obj = NullableJSONModel.objects.create(value=Value("[]"))
|
| 226 |
+
obj.refresh_from_db()
|
| 227 |
+
self.assertEqual(obj.value, [])
|
| 228 |
+
|
| 229 |
+
@skipUnlessDBFeature("supports_primitives_in_json_field")
|
| 230 |
+
def test_value_str_primitives_deprecation(self):
|
| 231 |
+
msg = (
|
| 232 |
+
"Providing an encoded JSON string via Value() is deprecated. Use "
|
| 233 |
+
"Value(None, output_field=JSONField()) instead."
|
| 234 |
+
)
|
| 235 |
+
with self.assertWarnsMessage(RemovedInDjango51Warning, msg):
|
| 236 |
+
obj = NullableJSONModel.objects.create(value=Value("null"))
|
| 237 |
+
obj.refresh_from_db()
|
| 238 |
+
self.assertIsNone(obj.value)
|
| 239 |
+
obj = NullableJSONModel.objects.create(value=Value("invalid-json"))
|
| 240 |
+
obj.refresh_from_db()
|
| 241 |
+
self.assertEqual(obj.value, "invalid-json")
|
| 242 |
+
|
| 243 |
+
@skipUnlessDBFeature("supports_primitives_in_json_field")
|
| 244 |
+
def test_json_null_different_from_sql_null(self):
|
| 245 |
+
json_null = NullableJSONModel.objects.create(value=Value(None, JSONField()))
|
| 246 |
+
NullableJSONModel.objects.update(value=Value(None, JSONField()))
|
| 247 |
+
json_null.refresh_from_db()
|
| 248 |
+
sql_null = NullableJSONModel.objects.create(value=None)
|
| 249 |
+
sql_null.refresh_from_db()
|
| 250 |
+
# 'null' is not equal to NULL in the database.
|
| 251 |
+
self.assertSequenceEqual(
|
| 252 |
+
NullableJSONModel.objects.filter(value=Value(None, JSONField())),
|
| 253 |
+
[json_null],
|
| 254 |
+
)
|
| 255 |
+
self.assertSequenceEqual(
|
| 256 |
+
NullableJSONModel.objects.filter(value=None),
|
| 257 |
+
[json_null],
|
| 258 |
+
)
|
| 259 |
+
self.assertSequenceEqual(
|
| 260 |
+
NullableJSONModel.objects.filter(value__isnull=True),
|
| 261 |
+
[sql_null],
|
| 262 |
+
)
|
| 263 |
+
# 'null' is equal to NULL in Python (None).
|
| 264 |
+
self.assertEqual(json_null.value, sql_null.value)
|
| 265 |
+
|
| 266 |
+
@skipUnlessDBFeature("supports_primitives_in_json_field")
|
| 267 |
+
def test_primitives(self):
|
| 268 |
+
values = [
|
| 269 |
+
True,
|
| 270 |
+
1,
|
| 271 |
+
1.45,
|
| 272 |
+
"String",
|
| 273 |
+
"",
|
| 274 |
+
]
|
| 275 |
+
for value in values:
|
| 276 |
+
with self.subTest(value=value):
|
| 277 |
+
obj = JSONModel(value=value)
|
| 278 |
+
obj.save()
|
| 279 |
+
obj.refresh_from_db()
|
| 280 |
+
self.assertEqual(obj.value, value)
|
| 281 |
+
|
| 282 |
+
def test_dict(self):
|
| 283 |
+
values = [
|
| 284 |
+
{},
|
| 285 |
+
{"name": "John", "age": 20, "height": 180.3},
|
| 286 |
+
{"a": True, "b": {"b1": False, "b2": None}},
|
| 287 |
+
]
|
| 288 |
+
for value in values:
|
| 289 |
+
with self.subTest(value=value):
|
| 290 |
+
obj = JSONModel.objects.create(value=value)
|
| 291 |
+
obj.refresh_from_db()
|
| 292 |
+
self.assertEqual(obj.value, value)
|
| 293 |
+
|
| 294 |
+
def test_list(self):
|
| 295 |
+
values = [
|
| 296 |
+
[],
|
| 297 |
+
["John", 20, 180.3],
|
| 298 |
+
[True, [False, None]],
|
| 299 |
+
]
|
| 300 |
+
for value in values:
|
| 301 |
+
with self.subTest(value=value):
|
| 302 |
+
obj = JSONModel.objects.create(value=value)
|
| 303 |
+
obj.refresh_from_db()
|
| 304 |
+
self.assertEqual(obj.value, value)
|
| 305 |
+
|
| 306 |
+
def test_realistic_object(self):
|
| 307 |
+
value = {
|
| 308 |
+
"name": "John",
|
| 309 |
+
"age": 20,
|
| 310 |
+
"pets": [
|
| 311 |
+
{"name": "Kit", "type": "cat", "age": 2},
|
| 312 |
+
{"name": "Max", "type": "dog", "age": 1},
|
| 313 |
+
],
|
| 314 |
+
"courses": [
|
| 315 |
+
["A1", "A2", "A3"],
|
| 316 |
+
["B1", "B2"],
|
| 317 |
+
["C1"],
|
| 318 |
+
],
|
| 319 |
+
}
|
| 320 |
+
obj = JSONModel.objects.create(value=value)
|
| 321 |
+
obj.refresh_from_db()
|
| 322 |
+
self.assertEqual(obj.value, value)
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
@skipUnlessDBFeature("supports_json_field")
|
| 326 |
+
class TestQuerying(TestCase):
|
| 327 |
+
@classmethod
|
| 328 |
+
def setUpTestData(cls):
|
| 329 |
+
cls.primitives = [True, False, "yes", 7, 9.6]
|
| 330 |
+
values = [
|
| 331 |
+
None,
|
| 332 |
+
[],
|
| 333 |
+
{},
|
| 334 |
+
{"a": "b", "c": 14},
|
| 335 |
+
{
|
| 336 |
+
"a": "b",
|
| 337 |
+
"c": 14,
|
| 338 |
+
"d": ["e", {"f": "g"}],
|
| 339 |
+
"h": True,
|
| 340 |
+
"i": False,
|
| 341 |
+
"j": None,
|
| 342 |
+
"k": {"l": "m"},
|
| 343 |
+
"n": [None, True, False],
|
| 344 |
+
"o": '"quoted"',
|
| 345 |
+
"p": 4.2,
|
| 346 |
+
"r": {"s": True, "t": False},
|
| 347 |
+
},
|
| 348 |
+
[1, [2]],
|
| 349 |
+
{"k": True, "l": False, "foo": "bax"},
|
| 350 |
+
{
|
| 351 |
+
"foo": "bar",
|
| 352 |
+
"baz": {"a": "b", "c": "d"},
|
| 353 |
+
"bar": ["foo", "bar"],
|
| 354 |
+
"bax": {"foo": "bar"},
|
| 355 |
+
},
|
| 356 |
+
]
|
| 357 |
+
cls.objs = [NullableJSONModel.objects.create(value=value) for value in values]
|
| 358 |
+
if connection.features.supports_primitives_in_json_field:
|
| 359 |
+
cls.objs.extend(
|
| 360 |
+
[
|
| 361 |
+
NullableJSONModel.objects.create(value=value)
|
| 362 |
+
for value in cls.primitives
|
| 363 |
+
]
|
| 364 |
+
)
|
| 365 |
+
cls.raw_sql = "%s::jsonb" if connection.vendor == "postgresql" else "%s"
|
| 366 |
+
|
| 367 |
+
def test_exact(self):
|
| 368 |
+
self.assertSequenceEqual(
|
| 369 |
+
NullableJSONModel.objects.filter(value__exact={}),
|
| 370 |
+
[self.objs[2]],
|
| 371 |
+
)
|
| 372 |
+
|
| 373 |
+
def test_exact_complex(self):
|
| 374 |
+
self.assertSequenceEqual(
|
| 375 |
+
NullableJSONModel.objects.filter(value__exact={"a": "b", "c": 14}),
|
| 376 |
+
[self.objs[3]],
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
def test_icontains(self):
|
| 380 |
+
self.assertCountEqual(
|
| 381 |
+
NullableJSONModel.objects.filter(value__icontains="BaX"),
|
| 382 |
+
self.objs[6:8],
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
def test_isnull(self):
|
| 386 |
+
self.assertSequenceEqual(
|
| 387 |
+
NullableJSONModel.objects.filter(value__isnull=True),
|
| 388 |
+
[self.objs[0]],
|
| 389 |
+
)
|
| 390 |
+
|
| 391 |
+
def test_ordering_by_transform(self):
|
| 392 |
+
mariadb = connection.vendor == "mysql" and connection.mysql_is_mariadb
|
| 393 |
+
values = [
|
| 394 |
+
{"ord": 93, "name": "bar"},
|
| 395 |
+
{"ord": 22.1, "name": "foo"},
|
| 396 |
+
{"ord": -1, "name": "baz"},
|
| 397 |
+
{"ord": 21.931902, "name": "spam"},
|
| 398 |
+
{"ord": -100291029, "name": "eggs"},
|
| 399 |
+
]
|
| 400 |
+
for field_name in ["value", "value_custom"]:
|
| 401 |
+
with self.subTest(field=field_name):
|
| 402 |
+
objs = [
|
| 403 |
+
NullableJSONModel.objects.create(**{field_name: value})
|
| 404 |
+
for value in values
|
| 405 |
+
]
|
| 406 |
+
query = NullableJSONModel.objects.filter(
|
| 407 |
+
**{"%s__name__isnull" % field_name: False},
|
| 408 |
+
).order_by("%s__ord" % field_name)
|
| 409 |
+
expected = [objs[4], objs[2], objs[3], objs[1], objs[0]]
|
| 410 |
+
if mariadb or connection.vendor == "oracle":
|
| 411 |
+
# MariaDB and Oracle return JSON values as strings.
|
| 412 |
+
expected = [objs[2], objs[4], objs[3], objs[1], objs[0]]
|
| 413 |
+
self.assertSequenceEqual(query, expected)
|
| 414 |
+
|
| 415 |
+
def test_ordering_grouping_by_key_transform(self):
|
| 416 |
+
base_qs = NullableJSONModel.objects.filter(value__d__0__isnull=False)
|
| 417 |
+
for qs in (
|
| 418 |
+
base_qs.order_by("value__d__0"),
|
| 419 |
+
base_qs.annotate(
|
| 420 |
+
key=KeyTransform("0", KeyTransform("d", "value"))
|
| 421 |
+
).order_by("key"),
|
| 422 |
+
):
|
| 423 |
+
self.assertSequenceEqual(qs, [self.objs[4]])
|
| 424 |
+
none_val = "" if connection.features.interprets_empty_strings_as_nulls else None
|
| 425 |
+
qs = NullableJSONModel.objects.filter(value__isnull=False)
|
| 426 |
+
self.assertQuerySetEqual(
|
| 427 |
+
qs.filter(value__isnull=False)
|
| 428 |
+
.annotate(key=KT("value__d__1__f"))
|
| 429 |
+
.values("key")
|
| 430 |
+
.annotate(count=Count("key"))
|
| 431 |
+
.order_by("count"),
|
| 432 |
+
[(none_val, 0), ("g", 1)],
|
| 433 |
+
operator.itemgetter("key", "count"),
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
def test_ordering_grouping_by_count(self):
|
| 437 |
+
qs = (
|
| 438 |
+
NullableJSONModel.objects.filter(
|
| 439 |
+
value__isnull=False,
|
| 440 |
+
)
|
| 441 |
+
.values("value__d__0")
|
| 442 |
+
.annotate(count=Count("value__d__0"))
|
| 443 |
+
.order_by("count")
|
| 444 |
+
)
|
| 445 |
+
self.assertQuerySetEqual(qs, [0, 1], operator.itemgetter("count"))
|
| 446 |
+
|
| 447 |
+
def test_order_grouping_custom_decoder(self):
|
| 448 |
+
NullableJSONModel.objects.create(value_custom={"a": "b"})
|
| 449 |
+
qs = NullableJSONModel.objects.filter(value_custom__isnull=False)
|
| 450 |
+
self.assertSequenceEqual(
|
| 451 |
+
qs.values(
|
| 452 |
+
"value_custom__a",
|
| 453 |
+
)
|
| 454 |
+
.annotate(
|
| 455 |
+
count=Count("id"),
|
| 456 |
+
)
|
| 457 |
+
.order_by("value_custom__a"),
|
| 458 |
+
[{"value_custom__a": "b", "count": 1}],
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
def test_key_transform_raw_expression(self):
|
| 462 |
+
expr = RawSQL(self.raw_sql, ['{"x": "bar"}'])
|
| 463 |
+
self.assertSequenceEqual(
|
| 464 |
+
NullableJSONModel.objects.filter(value__foo=KeyTransform("x", expr)),
|
| 465 |
+
[self.objs[7]],
|
| 466 |
+
)
|
| 467 |
+
|
| 468 |
+
def test_nested_key_transform_raw_expression(self):
|
| 469 |
+
expr = RawSQL(self.raw_sql, ['{"x": {"y": "bar"}}'])
|
| 470 |
+
self.assertSequenceEqual(
|
| 471 |
+
NullableJSONModel.objects.filter(
|
| 472 |
+
value__foo=KeyTransform("y", KeyTransform("x", expr))
|
| 473 |
+
),
|
| 474 |
+
[self.objs[7]],
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
+
def test_key_transform_expression(self):
|
| 478 |
+
self.assertSequenceEqual(
|
| 479 |
+
NullableJSONModel.objects.filter(value__d__0__isnull=False)
|
| 480 |
+
.annotate(
|
| 481 |
+
key=KeyTransform("d", "value"),
|
| 482 |
+
chain=KeyTransform("0", "key"),
|
| 483 |
+
expr=KeyTransform("0", Cast("key", models.JSONField())),
|
| 484 |
+
)
|
| 485 |
+
.filter(chain=F("expr")),
|
| 486 |
+
[self.objs[4]],
|
| 487 |
+
)
|
| 488 |
+
|
| 489 |
+
def test_key_transform_annotation_expression(self):
|
| 490 |
+
obj = NullableJSONModel.objects.create(value={"d": ["e", "e"]})
|
| 491 |
+
self.assertSequenceEqual(
|
| 492 |
+
NullableJSONModel.objects.filter(value__d__0__isnull=False)
|
| 493 |
+
.annotate(
|
| 494 |
+
key=F("value__d"),
|
| 495 |
+
chain=F("key__0"),
|
| 496 |
+
expr=Cast("key", models.JSONField()),
|
| 497 |
+
)
|
| 498 |
+
.filter(chain=F("expr__1")),
|
| 499 |
+
[obj],
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
def test_nested_key_transform_expression(self):
|
| 503 |
+
self.assertSequenceEqual(
|
| 504 |
+
NullableJSONModel.objects.filter(value__d__0__isnull=False)
|
| 505 |
+
.annotate(
|
| 506 |
+
key=KeyTransform("d", "value"),
|
| 507 |
+
chain=KeyTransform("f", KeyTransform("1", "key")),
|
| 508 |
+
expr=KeyTransform(
|
| 509 |
+
"f", KeyTransform("1", Cast("key", models.JSONField()))
|
| 510 |
+
),
|
| 511 |
+
)
|
| 512 |
+
.filter(chain=F("expr")),
|
| 513 |
+
[self.objs[4]],
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
def test_nested_key_transform_annotation_expression(self):
|
| 517 |
+
obj = NullableJSONModel.objects.create(
|
| 518 |
+
value={"d": ["e", {"f": "g"}, {"f": "g"}]},
|
| 519 |
+
)
|
| 520 |
+
self.assertSequenceEqual(
|
| 521 |
+
NullableJSONModel.objects.filter(value__d__0__isnull=False)
|
| 522 |
+
.annotate(
|
| 523 |
+
key=F("value__d"),
|
| 524 |
+
chain=F("key__1__f"),
|
| 525 |
+
expr=Cast("key", models.JSONField()),
|
| 526 |
+
)
|
| 527 |
+
.filter(chain=F("expr__2__f")),
|
| 528 |
+
[obj],
|
| 529 |
+
)
|
| 530 |
+
|
| 531 |
+
def test_nested_key_transform_on_subquery(self):
|
| 532 |
+
self.assertSequenceEqual(
|
| 533 |
+
NullableJSONModel.objects.filter(value__d__0__isnull=False)
|
| 534 |
+
.annotate(
|
| 535 |
+
subquery_value=Subquery(
|
| 536 |
+
NullableJSONModel.objects.filter(pk=OuterRef("pk")).values("value")
|
| 537 |
+
),
|
| 538 |
+
key=KeyTransform("d", "subquery_value"),
|
| 539 |
+
chain=KeyTransform("f", KeyTransform("1", "key")),
|
| 540 |
+
)
|
| 541 |
+
.filter(chain="g"),
|
| 542 |
+
[self.objs[4]],
|
| 543 |
+
)
|
| 544 |
+
|
| 545 |
+
def test_key_text_transform_char_lookup(self):
|
| 546 |
+
qs = NullableJSONModel.objects.annotate(
|
| 547 |
+
char_value=KeyTextTransform("foo", "value"),
|
| 548 |
+
).filter(char_value__startswith="bar")
|
| 549 |
+
self.assertSequenceEqual(qs, [self.objs[7]])
|
| 550 |
+
|
| 551 |
+
qs = NullableJSONModel.objects.annotate(
|
| 552 |
+
char_value=KeyTextTransform(1, KeyTextTransform("bar", "value")),
|
| 553 |
+
).filter(char_value__startswith="bar")
|
| 554 |
+
self.assertSequenceEqual(qs, [self.objs[7]])
|
| 555 |
+
|
| 556 |
+
def test_expression_wrapper_key_transform(self):
|
| 557 |
+
self.assertCountEqual(
|
| 558 |
+
NullableJSONModel.objects.annotate(
|
| 559 |
+
expr=ExpressionWrapper(
|
| 560 |
+
KeyTransform("c", "value"),
|
| 561 |
+
output_field=IntegerField(),
|
| 562 |
+
),
|
| 563 |
+
).filter(expr__isnull=False),
|
| 564 |
+
self.objs[3:5],
|
| 565 |
+
)
|
| 566 |
+
|
| 567 |
+
def test_has_key(self):
|
| 568 |
+
self.assertCountEqual(
|
| 569 |
+
NullableJSONModel.objects.filter(value__has_key="a"),
|
| 570 |
+
[self.objs[3], self.objs[4]],
|
| 571 |
+
)
|
| 572 |
+
|
| 573 |
+
def test_has_key_null_value(self):
|
| 574 |
+
self.assertSequenceEqual(
|
| 575 |
+
NullableJSONModel.objects.filter(value__has_key="j"),
|
| 576 |
+
[self.objs[4]],
|
| 577 |
+
)
|
| 578 |
+
|
| 579 |
+
def test_has_key_deep(self):
|
| 580 |
+
tests = [
|
| 581 |
+
(Q(value__baz__has_key="a"), self.objs[7]),
|
| 582 |
+
(
|
| 583 |
+
Q(value__has_key=KeyTransform("a", KeyTransform("baz", "value"))),
|
| 584 |
+
self.objs[7],
|
| 585 |
+
),
|
| 586 |
+
(Q(value__has_key=F("value__baz__a")), self.objs[7]),
|
| 587 |
+
(
|
| 588 |
+
Q(value__has_key=KeyTransform("c", KeyTransform("baz", "value"))),
|
| 589 |
+
self.objs[7],
|
| 590 |
+
),
|
| 591 |
+
(Q(value__has_key=F("value__baz__c")), self.objs[7]),
|
| 592 |
+
(Q(value__d__1__has_key="f"), self.objs[4]),
|
| 593 |
+
(
|
| 594 |
+
Q(
|
| 595 |
+
value__has_key=KeyTransform(
|
| 596 |
+
"f", KeyTransform("1", KeyTransform("d", "value"))
|
| 597 |
+
)
|
| 598 |
+
),
|
| 599 |
+
self.objs[4],
|
| 600 |
+
),
|
| 601 |
+
(Q(value__has_key=F("value__d__1__f")), self.objs[4]),
|
| 602 |
+
]
|
| 603 |
+
for condition, expected in tests:
|
| 604 |
+
with self.subTest(condition=condition):
|
| 605 |
+
self.assertSequenceEqual(
|
| 606 |
+
NullableJSONModel.objects.filter(condition),
|
| 607 |
+
[expected],
|
| 608 |
+
)
|
| 609 |
+
|
| 610 |
+
def test_has_key_list(self):
|
| 611 |
+
obj = NullableJSONModel.objects.create(value=[{"a": 1}, {"b": "x"}])
|
| 612 |
+
tests = [
|
| 613 |
+
Q(value__1__has_key="b"),
|
| 614 |
+
Q(value__has_key=KeyTransform("b", KeyTransform(1, "value"))),
|
| 615 |
+
Q(value__has_key=KeyTransform("b", KeyTransform("1", "value"))),
|
| 616 |
+
Q(value__has_key=F("value__1__b")),
|
| 617 |
+
]
|
| 618 |
+
for condition in tests:
|
| 619 |
+
with self.subTest(condition=condition):
|
| 620 |
+
self.assertSequenceEqual(
|
| 621 |
+
NullableJSONModel.objects.filter(condition),
|
| 622 |
+
[obj],
|
| 623 |
+
)
|
| 624 |
+
|
| 625 |
+
def test_has_keys(self):
|
| 626 |
+
self.assertSequenceEqual(
|
| 627 |
+
NullableJSONModel.objects.filter(value__has_keys=["a", "c", "h"]),
|
| 628 |
+
[self.objs[4]],
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
def test_has_any_keys(self):
|
| 632 |
+
self.assertCountEqual(
|
| 633 |
+
NullableJSONModel.objects.filter(value__has_any_keys=["c", "l"]),
|
| 634 |
+
[self.objs[3], self.objs[4], self.objs[6]],
|
| 635 |
+
)
|
| 636 |
+
|
| 637 |
+
def test_has_key_number(self):
|
| 638 |
+
obj = NullableJSONModel.objects.create(
|
| 639 |
+
value={
|
| 640 |
+
"123": "value",
|
| 641 |
+
"nested": {"456": "bar", "lorem": "abc", "999": True},
|
| 642 |
+
"array": [{"789": "baz", "777": "def", "ipsum": 200}],
|
| 643 |
+
"000": "val",
|
| 644 |
+
}
|
| 645 |
+
)
|
| 646 |
+
tests = [
|
| 647 |
+
Q(value__has_key="123"),
|
| 648 |
+
Q(value__nested__has_key="456"),
|
| 649 |
+
Q(value__array__0__has_key="789"),
|
| 650 |
+
Q(value__has_keys=["nested", "123", "array", "000"]),
|
| 651 |
+
Q(value__nested__has_keys=["lorem", "999", "456"]),
|
| 652 |
+
Q(value__array__0__has_keys=["789", "ipsum", "777"]),
|
| 653 |
+
Q(value__has_any_keys=["000", "nonexistent"]),
|
| 654 |
+
Q(value__nested__has_any_keys=["999", "nonexistent"]),
|
| 655 |
+
Q(value__array__0__has_any_keys=["777", "nonexistent"]),
|
| 656 |
+
]
|
| 657 |
+
for condition in tests:
|
| 658 |
+
with self.subTest(condition=condition):
|
| 659 |
+
self.assertSequenceEqual(
|
| 660 |
+
NullableJSONModel.objects.filter(condition),
|
| 661 |
+
[obj],
|
| 662 |
+
)
|
| 663 |
+
|
| 664 |
+
@skipUnlessDBFeature("supports_json_field_contains")
|
| 665 |
+
def test_contains(self):
|
| 666 |
+
tests = [
|
| 667 |
+
({}, self.objs[2:5] + self.objs[6:8]),
|
| 668 |
+
({"baz": {"a": "b", "c": "d"}}, [self.objs[7]]),
|
| 669 |
+
({"baz": {"a": "b"}}, [self.objs[7]]),
|
| 670 |
+
({"baz": {"c": "d"}}, [self.objs[7]]),
|
| 671 |
+
({"k": True, "l": False}, [self.objs[6]]),
|
| 672 |
+
({"d": ["e", {"f": "g"}]}, [self.objs[4]]),
|
| 673 |
+
({"d": ["e"]}, [self.objs[4]]),
|
| 674 |
+
({"d": [{"f": "g"}]}, [self.objs[4]]),
|
| 675 |
+
([1, [2]], [self.objs[5]]),
|
| 676 |
+
([1], [self.objs[5]]),
|
| 677 |
+
([[2]], [self.objs[5]]),
|
| 678 |
+
({"n": [None, True, False]}, [self.objs[4]]),
|
| 679 |
+
({"j": None}, [self.objs[4]]),
|
| 680 |
+
]
|
| 681 |
+
for value, expected in tests:
|
| 682 |
+
with self.subTest(value=value):
|
| 683 |
+
qs = NullableJSONModel.objects.filter(value__contains=value)
|
| 684 |
+
self.assertCountEqual(qs, expected)
|
| 685 |
+
|
| 686 |
+
@skipIfDBFeature("supports_json_field_contains")
|
| 687 |
+
def test_contains_unsupported(self):
|
| 688 |
+
msg = "contains lookup is not supported on this database backend."
|
| 689 |
+
with self.assertRaisesMessage(NotSupportedError, msg):
|
| 690 |
+
NullableJSONModel.objects.filter(
|
| 691 |
+
value__contains={"baz": {"a": "b", "c": "d"}},
|
| 692 |
+
).get()
|
| 693 |
+
|
| 694 |
+
@skipUnlessDBFeature(
|
| 695 |
+
"supports_primitives_in_json_field",
|
| 696 |
+
"supports_json_field_contains",
|
| 697 |
+
)
|
| 698 |
+
def test_contains_primitives(self):
|
| 699 |
+
for value in self.primitives:
|
| 700 |
+
with self.subTest(value=value):
|
| 701 |
+
qs = NullableJSONModel.objects.filter(value__contains=value)
|
| 702 |
+
self.assertIs(qs.exists(), True)
|
| 703 |
+
|
| 704 |
+
@skipUnlessDBFeature("supports_json_field_contains")
|
| 705 |
+
def test_contained_by(self):
|
| 706 |
+
qs = NullableJSONModel.objects.filter(
|
| 707 |
+
value__contained_by={"a": "b", "c": 14, "h": True}
|
| 708 |
+
)
|
| 709 |
+
self.assertCountEqual(qs, self.objs[2:4])
|
| 710 |
+
|
| 711 |
+
@skipIfDBFeature("supports_json_field_contains")
|
| 712 |
+
def test_contained_by_unsupported(self):
|
| 713 |
+
msg = "contained_by lookup is not supported on this database backend."
|
| 714 |
+
with self.assertRaisesMessage(NotSupportedError, msg):
|
| 715 |
+
NullableJSONModel.objects.filter(value__contained_by={"a": "b"}).get()
|
| 716 |
+
|
| 717 |
+
def test_deep_values(self):
|
| 718 |
+
qs = NullableJSONModel.objects.values_list("value__k__l").order_by("pk")
|
| 719 |
+
expected_objs = [(None,)] * len(self.objs)
|
| 720 |
+
expected_objs[4] = ("m",)
|
| 721 |
+
self.assertSequenceEqual(qs, expected_objs)
|
| 722 |
+
|
| 723 |
+
@skipUnlessDBFeature("can_distinct_on_fields")
|
| 724 |
+
def test_deep_distinct(self):
|
| 725 |
+
query = NullableJSONModel.objects.distinct("value__k__l").values_list(
|
| 726 |
+
"value__k__l"
|
| 727 |
+
)
|
| 728 |
+
self.assertSequenceEqual(query, [("m",), (None,)])
|
| 729 |
+
|
| 730 |
+
def test_isnull_key(self):
|
| 731 |
+
# key__isnull=False works the same as has_key='key'.
|
| 732 |
+
self.assertCountEqual(
|
| 733 |
+
NullableJSONModel.objects.filter(value__a__isnull=True),
|
| 734 |
+
self.objs[:3] + self.objs[5:],
|
| 735 |
+
)
|
| 736 |
+
self.assertCountEqual(
|
| 737 |
+
NullableJSONModel.objects.filter(value__j__isnull=True),
|
| 738 |
+
self.objs[:4] + self.objs[5:],
|
| 739 |
+
)
|
| 740 |
+
self.assertCountEqual(
|
| 741 |
+
NullableJSONModel.objects.filter(value__a__isnull=False),
|
| 742 |
+
[self.objs[3], self.objs[4]],
|
| 743 |
+
)
|
| 744 |
+
self.assertSequenceEqual(
|
| 745 |
+
NullableJSONModel.objects.filter(value__j__isnull=False),
|
| 746 |
+
[self.objs[4]],
|
| 747 |
+
)
|
| 748 |
+
|
| 749 |
+
def test_isnull_key_or_none(self):
|
| 750 |
+
obj = NullableJSONModel.objects.create(value={"a": None})
|
| 751 |
+
self.assertCountEqual(
|
| 752 |
+
NullableJSONModel.objects.filter(
|
| 753 |
+
Q(value__a__isnull=True) | Q(value__a=None)
|
| 754 |
+
),
|
| 755 |
+
self.objs[:3] + self.objs[5:] + [obj],
|
| 756 |
+
)
|
| 757 |
+
|
| 758 |
+
def test_none_key(self):
|
| 759 |
+
self.assertSequenceEqual(
|
| 760 |
+
NullableJSONModel.objects.filter(value__j=None),
|
| 761 |
+
[self.objs[4]],
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
def test_none_key_exclude(self):
|
| 765 |
+
obj = NullableJSONModel.objects.create(value={"j": 1})
|
| 766 |
+
if connection.vendor == "oracle":
|
| 767 |
+
# Oracle supports filtering JSON objects with NULL keys, but the
|
| 768 |
+
# current implementation doesn't support it.
|
| 769 |
+
self.assertSequenceEqual(
|
| 770 |
+
NullableJSONModel.objects.exclude(value__j=None),
|
| 771 |
+
self.objs[1:4] + self.objs[5:] + [obj],
|
| 772 |
+
)
|
| 773 |
+
else:
|
| 774 |
+
self.assertSequenceEqual(
|
| 775 |
+
NullableJSONModel.objects.exclude(value__j=None), [obj]
|
| 776 |
+
)
|
| 777 |
+
|
| 778 |
+
def test_shallow_list_lookup(self):
|
| 779 |
+
self.assertSequenceEqual(
|
| 780 |
+
NullableJSONModel.objects.filter(value__0=1),
|
| 781 |
+
[self.objs[5]],
|
| 782 |
+
)
|
| 783 |
+
|
| 784 |
+
def test_shallow_obj_lookup(self):
|
| 785 |
+
self.assertCountEqual(
|
| 786 |
+
NullableJSONModel.objects.filter(value__a="b"),
|
| 787 |
+
[self.objs[3], self.objs[4]],
|
| 788 |
+
)
|
| 789 |
+
|
| 790 |
+
def test_obj_subquery_lookup(self):
|
| 791 |
+
qs = NullableJSONModel.objects.annotate(
|
| 792 |
+
field=Subquery(
|
| 793 |
+
NullableJSONModel.objects.filter(pk=OuterRef("pk")).values("value")
|
| 794 |
+
),
|
| 795 |
+
).filter(field__a="b")
|
| 796 |
+
self.assertCountEqual(qs, [self.objs[3], self.objs[4]])
|
| 797 |
+
|
| 798 |
+
def test_deep_lookup_objs(self):
|
| 799 |
+
self.assertSequenceEqual(
|
| 800 |
+
NullableJSONModel.objects.filter(value__k__l="m"),
|
| 801 |
+
[self.objs[4]],
|
| 802 |
+
)
|
| 803 |
+
|
| 804 |
+
def test_shallow_lookup_obj_target(self):
|
| 805 |
+
self.assertSequenceEqual(
|
| 806 |
+
NullableJSONModel.objects.filter(value__k={"l": "m"}),
|
| 807 |
+
[self.objs[4]],
|
| 808 |
+
)
|
| 809 |
+
|
| 810 |
+
def test_deep_lookup_array(self):
|
| 811 |
+
self.assertSequenceEqual(
|
| 812 |
+
NullableJSONModel.objects.filter(value__1__0=2),
|
| 813 |
+
[self.objs[5]],
|
| 814 |
+
)
|
| 815 |
+
|
| 816 |
+
def test_deep_lookup_mixed(self):
|
| 817 |
+
self.assertSequenceEqual(
|
| 818 |
+
NullableJSONModel.objects.filter(value__d__1__f="g"),
|
| 819 |
+
[self.objs[4]],
|
| 820 |
+
)
|
| 821 |
+
|
| 822 |
+
def test_deep_lookup_transform(self):
|
| 823 |
+
self.assertCountEqual(
|
| 824 |
+
NullableJSONModel.objects.filter(value__c__gt=2),
|
| 825 |
+
[self.objs[3], self.objs[4]],
|
| 826 |
+
)
|
| 827 |
+
self.assertCountEqual(
|
| 828 |
+
NullableJSONModel.objects.filter(value__c__gt=2.33),
|
| 829 |
+
[self.objs[3], self.objs[4]],
|
| 830 |
+
)
|
| 831 |
+
self.assertIs(NullableJSONModel.objects.filter(value__c__lt=5).exists(), False)
|
| 832 |
+
|
| 833 |
+
def test_lookup_exclude(self):
|
| 834 |
+
tests = [
|
| 835 |
+
(Q(value__a="b"), [self.objs[0]]),
|
| 836 |
+
(Q(value__foo="bax"), [self.objs[0], self.objs[7]]),
|
| 837 |
+
]
|
| 838 |
+
for condition, expected in tests:
|
| 839 |
+
self.assertCountEqual(
|
| 840 |
+
NullableJSONModel.objects.exclude(condition),
|
| 841 |
+
expected,
|
| 842 |
+
)
|
| 843 |
+
self.assertCountEqual(
|
| 844 |
+
NullableJSONModel.objects.filter(~condition),
|
| 845 |
+
expected,
|
| 846 |
+
)
|
| 847 |
+
|
| 848 |
+
def test_lookup_exclude_nonexistent_key(self):
|
| 849 |
+
# Values without the key are ignored.
|
| 850 |
+
condition = Q(value__foo="bax")
|
| 851 |
+
objs_with_value = [self.objs[6]]
|
| 852 |
+
objs_with_different_value = [self.objs[0], self.objs[7]]
|
| 853 |
+
self.assertCountEqual(
|
| 854 |
+
NullableJSONModel.objects.exclude(condition),
|
| 855 |
+
objs_with_different_value,
|
| 856 |
+
)
|
| 857 |
+
self.assertSequenceEqual(
|
| 858 |
+
NullableJSONModel.objects.exclude(~condition),
|
| 859 |
+
objs_with_value,
|
| 860 |
+
)
|
| 861 |
+
self.assertCountEqual(
|
| 862 |
+
NullableJSONModel.objects.filter(condition | ~condition),
|
| 863 |
+
objs_with_value + objs_with_different_value,
|
| 864 |
+
)
|
| 865 |
+
self.assertCountEqual(
|
| 866 |
+
NullableJSONModel.objects.exclude(condition & ~condition),
|
| 867 |
+
objs_with_value + objs_with_different_value,
|
| 868 |
+
)
|
| 869 |
+
# Add the __isnull lookup to get an exhaustive set.
|
| 870 |
+
self.assertCountEqual(
|
| 871 |
+
NullableJSONModel.objects.exclude(condition & Q(value__foo__isnull=False)),
|
| 872 |
+
self.objs[0:6] + self.objs[7:],
|
| 873 |
+
)
|
| 874 |
+
self.assertSequenceEqual(
|
| 875 |
+
NullableJSONModel.objects.filter(condition & Q(value__foo__isnull=False)),
|
| 876 |
+
objs_with_value,
|
| 877 |
+
)
|
| 878 |
+
|
| 879 |
+
def test_usage_in_subquery(self):
|
| 880 |
+
self.assertCountEqual(
|
| 881 |
+
NullableJSONModel.objects.filter(
|
| 882 |
+
id__in=NullableJSONModel.objects.filter(value__c=14),
|
| 883 |
+
),
|
| 884 |
+
self.objs[3:5],
|
| 885 |
+
)
|
| 886 |
+
|
| 887 |
+
@skipUnlessDBFeature("supports_json_field_contains")
|
| 888 |
+
def test_array_key_contains(self):
|
| 889 |
+
tests = [
|
| 890 |
+
([], [self.objs[7]]),
|
| 891 |
+
("bar", [self.objs[7]]),
|
| 892 |
+
(["bar"], [self.objs[7]]),
|
| 893 |
+
("ar", []),
|
| 894 |
+
]
|
| 895 |
+
for value, expected in tests:
|
| 896 |
+
with self.subTest(value=value):
|
| 897 |
+
self.assertSequenceEqual(
|
| 898 |
+
NullableJSONModel.objects.filter(value__bar__contains=value),
|
| 899 |
+
expected,
|
| 900 |
+
)
|
| 901 |
+
|
| 902 |
+
def test_key_iexact(self):
|
| 903 |
+
self.assertIs(
|
| 904 |
+
NullableJSONModel.objects.filter(value__foo__iexact="BaR").exists(), True
|
| 905 |
+
)
|
| 906 |
+
self.assertIs(
|
| 907 |
+
NullableJSONModel.objects.filter(value__foo__iexact='"BaR"').exists(), False
|
| 908 |
+
)
|
| 909 |
+
|
| 910 |
+
def test_key_in(self):
|
| 911 |
+
tests = [
|
| 912 |
+
("value__c__in", [14], self.objs[3:5]),
|
| 913 |
+
("value__c__in", [14, 15], self.objs[3:5]),
|
| 914 |
+
("value__0__in", [1], [self.objs[5]]),
|
| 915 |
+
("value__0__in", [1, 3], [self.objs[5]]),
|
| 916 |
+
("value__foo__in", ["bar"], [self.objs[7]]),
|
| 917 |
+
(
|
| 918 |
+
"value__foo__in",
|
| 919 |
+
[KeyTransform("foo", KeyTransform("bax", "value"))],
|
| 920 |
+
[self.objs[7]],
|
| 921 |
+
),
|
| 922 |
+
("value__foo__in", [F("value__bax__foo")], [self.objs[7]]),
|
| 923 |
+
(
|
| 924 |
+
"value__foo__in",
|
| 925 |
+
[KeyTransform("foo", KeyTransform("bax", "value")), "baz"],
|
| 926 |
+
[self.objs[7]],
|
| 927 |
+
),
|
| 928 |
+
("value__foo__in", [F("value__bax__foo"), "baz"], [self.objs[7]]),
|
| 929 |
+
("value__foo__in", ["bar", "baz"], [self.objs[7]]),
|
| 930 |
+
("value__bar__in", [["foo", "bar"]], [self.objs[7]]),
|
| 931 |
+
("value__bar__in", [["foo", "bar"], ["a"]], [self.objs[7]]),
|
| 932 |
+
("value__bax__in", [{"foo": "bar"}, {"a": "b"}], [self.objs[7]]),
|
| 933 |
+
("value__h__in", [True, "foo"], [self.objs[4]]),
|
| 934 |
+
("value__i__in", [False, "foo"], [self.objs[4]]),
|
| 935 |
+
]
|
| 936 |
+
for lookup, value, expected in tests:
|
| 937 |
+
with self.subTest(lookup=lookup, value=value):
|
| 938 |
+
self.assertCountEqual(
|
| 939 |
+
NullableJSONModel.objects.filter(**{lookup: value}),
|
| 940 |
+
expected,
|
| 941 |
+
)
|
| 942 |
+
|
| 943 |
+
def test_key_values(self):
|
| 944 |
+
qs = NullableJSONModel.objects.filter(value__h=True)
|
| 945 |
+
tests = [
|
| 946 |
+
("value__a", "b"),
|
| 947 |
+
("value__c", 14),
|
| 948 |
+
("value__d", ["e", {"f": "g"}]),
|
| 949 |
+
("value__h", True),
|
| 950 |
+
("value__i", False),
|
| 951 |
+
("value__j", None),
|
| 952 |
+
("value__k", {"l": "m"}),
|
| 953 |
+
("value__n", [None, True, False]),
|
| 954 |
+
("value__p", 4.2),
|
| 955 |
+
("value__r", {"s": True, "t": False}),
|
| 956 |
+
]
|
| 957 |
+
for lookup, expected in tests:
|
| 958 |
+
with self.subTest(lookup=lookup):
|
| 959 |
+
self.assertEqual(qs.values_list(lookup, flat=True).get(), expected)
|
| 960 |
+
|
| 961 |
+
def test_key_values_boolean(self):
|
| 962 |
+
qs = NullableJSONModel.objects.filter(value__h=True, value__i=False)
|
| 963 |
+
tests = [
|
| 964 |
+
("value__h", True),
|
| 965 |
+
("value__i", False),
|
| 966 |
+
]
|
| 967 |
+
for lookup, expected in tests:
|
| 968 |
+
with self.subTest(lookup=lookup):
|
| 969 |
+
self.assertIs(qs.values_list(lookup, flat=True).get(), expected)
|
| 970 |
+
|
| 971 |
+
@skipUnlessDBFeature("supports_json_field_contains")
|
| 972 |
+
def test_key_contains(self):
|
| 973 |
+
self.assertIs(
|
| 974 |
+
NullableJSONModel.objects.filter(value__foo__contains="ar").exists(), False
|
| 975 |
+
)
|
| 976 |
+
self.assertIs(
|
| 977 |
+
NullableJSONModel.objects.filter(value__foo__contains="bar").exists(), True
|
| 978 |
+
)
|
| 979 |
+
|
| 980 |
+
def test_key_icontains(self):
|
| 981 |
+
self.assertIs(
|
| 982 |
+
NullableJSONModel.objects.filter(value__foo__icontains="Ar").exists(), True
|
| 983 |
+
)
|
| 984 |
+
|
| 985 |
+
def test_key_startswith(self):
|
| 986 |
+
self.assertIs(
|
| 987 |
+
NullableJSONModel.objects.filter(value__foo__startswith="b").exists(), True
|
| 988 |
+
)
|
| 989 |
+
|
| 990 |
+
def test_key_istartswith(self):
|
| 991 |
+
self.assertIs(
|
| 992 |
+
NullableJSONModel.objects.filter(value__foo__istartswith="B").exists(), True
|
| 993 |
+
)
|
| 994 |
+
|
| 995 |
+
def test_key_endswith(self):
|
| 996 |
+
self.assertIs(
|
| 997 |
+
NullableJSONModel.objects.filter(value__foo__endswith="r").exists(), True
|
| 998 |
+
)
|
| 999 |
+
|
| 1000 |
+
def test_key_iendswith(self):
|
| 1001 |
+
self.assertIs(
|
| 1002 |
+
NullableJSONModel.objects.filter(value__foo__iendswith="R").exists(), True
|
| 1003 |
+
)
|
| 1004 |
+
|
| 1005 |
+
def test_key_regex(self):
|
| 1006 |
+
self.assertIs(
|
| 1007 |
+
NullableJSONModel.objects.filter(value__foo__regex=r"^bar$").exists(), True
|
| 1008 |
+
)
|
| 1009 |
+
|
| 1010 |
+
def test_key_iregex(self):
|
| 1011 |
+
self.assertIs(
|
| 1012 |
+
NullableJSONModel.objects.filter(value__foo__iregex=r"^bAr$").exists(), True
|
| 1013 |
+
)
|
| 1014 |
+
|
| 1015 |
+
def test_key_quoted_string(self):
|
| 1016 |
+
self.assertEqual(
|
| 1017 |
+
NullableJSONModel.objects.filter(value__o='"quoted"').get(),
|
| 1018 |
+
self.objs[4],
|
| 1019 |
+
)
|
| 1020 |
+
|
| 1021 |
+
@skipUnlessDBFeature("has_json_operators")
|
| 1022 |
+
def test_key_sql_injection(self):
|
| 1023 |
+
with CaptureQueriesContext(connection) as queries:
|
| 1024 |
+
self.assertIs(
|
| 1025 |
+
NullableJSONModel.objects.filter(
|
| 1026 |
+
**{
|
| 1027 |
+
"""value__test' = '"a"') OR 1 = 1 OR ('d""": "x",
|
| 1028 |
+
}
|
| 1029 |
+
).exists(),
|
| 1030 |
+
False,
|
| 1031 |
+
)
|
| 1032 |
+
self.assertIn(
|
| 1033 |
+
"""."value" -> 'test'' = ''"a"'') OR 1 = 1 OR (''d') = '"x"'""",
|
| 1034 |
+
queries[0]["sql"],
|
| 1035 |
+
)
|
| 1036 |
+
|
| 1037 |
+
@skipIfDBFeature("has_json_operators")
|
| 1038 |
+
def test_key_sql_injection_escape(self):
|
| 1039 |
+
query = str(
|
| 1040 |
+
JSONModel.objects.filter(
|
| 1041 |
+
**{
|
| 1042 |
+
"""value__test") = '"a"' OR 1 = 1 OR ("d""": "x",
|
| 1043 |
+
}
|
| 1044 |
+
).query
|
| 1045 |
+
)
|
| 1046 |
+
self.assertIn('"test\\"', query)
|
| 1047 |
+
self.assertIn('\\"d', query)
|
| 1048 |
+
|
| 1049 |
+
def test_key_escape(self):
|
| 1050 |
+
obj = NullableJSONModel.objects.create(value={"%total": 10})
|
| 1051 |
+
self.assertEqual(
|
| 1052 |
+
NullableJSONModel.objects.filter(**{"value__%total": 10}).get(), obj
|
| 1053 |
+
)
|
| 1054 |
+
|
| 1055 |
+
def test_none_key_and_exact_lookup(self):
|
| 1056 |
+
self.assertSequenceEqual(
|
| 1057 |
+
NullableJSONModel.objects.filter(value__a="b", value__j=None),
|
| 1058 |
+
[self.objs[4]],
|
| 1059 |
+
)
|
| 1060 |
+
|
| 1061 |
+
def test_lookups_with_key_transform(self):
|
| 1062 |
+
tests = (
|
| 1063 |
+
("value__baz__has_key", "c"),
|
| 1064 |
+
("value__baz__has_keys", ["a", "c"]),
|
| 1065 |
+
("value__baz__has_any_keys", ["a", "x"]),
|
| 1066 |
+
("value__has_key", KeyTextTransform("foo", "value")),
|
| 1067 |
+
)
|
| 1068 |
+
for lookup, value in tests:
|
| 1069 |
+
with self.subTest(lookup=lookup):
|
| 1070 |
+
self.assertIs(
|
| 1071 |
+
NullableJSONModel.objects.filter(
|
| 1072 |
+
**{lookup: value},
|
| 1073 |
+
).exists(),
|
| 1074 |
+
True,
|
| 1075 |
+
)
|
| 1076 |
+
|
| 1077 |
+
@skipUnlessDBFeature("supports_json_field_contains")
|
| 1078 |
+
def test_contains_contained_by_with_key_transform(self):
|
| 1079 |
+
tests = [
|
| 1080 |
+
("value__d__contains", "e"),
|
| 1081 |
+
("value__d__contains", [{"f": "g"}]),
|
| 1082 |
+
("value__contains", KeyTransform("bax", "value")),
|
| 1083 |
+
("value__contains", F("value__bax")),
|
| 1084 |
+
("value__baz__contains", {"a": "b"}),
|
| 1085 |
+
("value__baz__contained_by", {"a": "b", "c": "d", "e": "f"}),
|
| 1086 |
+
(
|
| 1087 |
+
"value__contained_by",
|
| 1088 |
+
KeyTransform(
|
| 1089 |
+
"x",
|
| 1090 |
+
RawSQL(
|
| 1091 |
+
self.raw_sql,
|
| 1092 |
+
['{"x": {"a": "b", "c": 1, "d": "e"}}'],
|
| 1093 |
+
),
|
| 1094 |
+
),
|
| 1095 |
+
),
|
| 1096 |
+
]
|
| 1097 |
+
# For databases where {'f': 'g'} (without surrounding []) matches
|
| 1098 |
+
# [{'f': 'g'}].
|
| 1099 |
+
if not connection.features.json_key_contains_list_matching_requires_list:
|
| 1100 |
+
tests.append(("value__d__contains", {"f": "g"}))
|
| 1101 |
+
for lookup, value in tests:
|
| 1102 |
+
with self.subTest(lookup=lookup, value=value):
|
| 1103 |
+
self.assertIs(
|
| 1104 |
+
NullableJSONModel.objects.filter(
|
| 1105 |
+
**{lookup: value},
|
| 1106 |
+
).exists(),
|
| 1107 |
+
True,
|
| 1108 |
+
)
|
| 1109 |
+
|
| 1110 |
+
def test_join_key_transform_annotation_expression(self):
|
| 1111 |
+
related_obj = RelatedJSONModel.objects.create(
|
| 1112 |
+
value={"d": ["f", "e"]},
|
| 1113 |
+
json_model=self.objs[4],
|
| 1114 |
+
)
|
| 1115 |
+
RelatedJSONModel.objects.create(
|
| 1116 |
+
value={"d": ["e", "f"]},
|
| 1117 |
+
json_model=self.objs[4],
|
| 1118 |
+
)
|
| 1119 |
+
self.assertSequenceEqual(
|
| 1120 |
+
RelatedJSONModel.objects.annotate(
|
| 1121 |
+
key=F("value__d"),
|
| 1122 |
+
related_key=F("json_model__value__d"),
|
| 1123 |
+
chain=F("key__1"),
|
| 1124 |
+
expr=Cast("key", models.JSONField()),
|
| 1125 |
+
).filter(chain=F("related_key__0")),
|
| 1126 |
+
[related_obj],
|
| 1127 |
+
)
|
| 1128 |
+
|
| 1129 |
+
def test_key_text_transform_from_lookup(self):
|
| 1130 |
+
qs = NullableJSONModel.objects.annotate(b=KT("value__bax__foo")).filter(
|
| 1131 |
+
b__contains="ar",
|
| 1132 |
+
)
|
| 1133 |
+
self.assertSequenceEqual(qs, [self.objs[7]])
|
| 1134 |
+
qs = NullableJSONModel.objects.annotate(c=KT("value__o")).filter(
|
| 1135 |
+
c__contains="uot",
|
| 1136 |
+
)
|
| 1137 |
+
self.assertSequenceEqual(qs, [self.objs[4]])
|
| 1138 |
+
|
| 1139 |
+
def test_key_text_transform_from_lookup_invalid(self):
|
| 1140 |
+
msg = "Lookup must contain key or index transforms."
|
| 1141 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 1142 |
+
KT("value")
|
| 1143 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 1144 |
+
KT("")
|
testbed/django__django/tests/model_fields/tests.py
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 1 |
+
import pickle
|
| 2 |
+
|
| 3 |
+
from django import forms
|
| 4 |
+
from django.core.exceptions import ValidationError
|
| 5 |
+
from django.db import models
|
| 6 |
+
from django.test import SimpleTestCase, TestCase
|
| 7 |
+
from django.utils.functional import lazy
|
| 8 |
+
|
| 9 |
+
from .models import (
|
| 10 |
+
Bar,
|
| 11 |
+
Choiceful,
|
| 12 |
+
Foo,
|
| 13 |
+
RenamedField,
|
| 14 |
+
VerboseNameField,
|
| 15 |
+
Whiz,
|
| 16 |
+
WhizDelayed,
|
| 17 |
+
WhizIter,
|
| 18 |
+
WhizIterEmpty,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class Nested:
|
| 23 |
+
class Field(models.Field):
|
| 24 |
+
pass
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class BasicFieldTests(SimpleTestCase):
|
| 28 |
+
def test_show_hidden_initial(self):
|
| 29 |
+
"""
|
| 30 |
+
Fields with choices respect show_hidden_initial as a kwarg to
|
| 31 |
+
formfield().
|
| 32 |
+
"""
|
| 33 |
+
choices = [(0, 0), (1, 1)]
|
| 34 |
+
model_field = models.Field(choices=choices)
|
| 35 |
+
form_field = model_field.formfield(show_hidden_initial=True)
|
| 36 |
+
self.assertTrue(form_field.show_hidden_initial)
|
| 37 |
+
|
| 38 |
+
form_field = model_field.formfield(show_hidden_initial=False)
|
| 39 |
+
self.assertFalse(form_field.show_hidden_initial)
|
| 40 |
+
|
| 41 |
+
def test_field_repr(self):
|
| 42 |
+
"""
|
| 43 |
+
__repr__() of a field displays its name.
|
| 44 |
+
"""
|
| 45 |
+
f = Foo._meta.get_field("a")
|
| 46 |
+
self.assertEqual(repr(f), "<django.db.models.fields.CharField: a>")
|
| 47 |
+
f = models.fields.CharField()
|
| 48 |
+
self.assertEqual(repr(f), "<django.db.models.fields.CharField>")
|
| 49 |
+
|
| 50 |
+
def test_field_repr_nested(self):
|
| 51 |
+
"""__repr__() uses __qualname__ for nested class support."""
|
| 52 |
+
self.assertEqual(repr(Nested.Field()), "<model_fields.tests.Nested.Field>")
|
| 53 |
+
|
| 54 |
+
def test_field_name(self):
|
| 55 |
+
"""
|
| 56 |
+
A defined field name (name="fieldname") is used instead of the model
|
| 57 |
+
model's attribute name (modelname).
|
| 58 |
+
"""
|
| 59 |
+
instance = RenamedField()
|
| 60 |
+
self.assertTrue(hasattr(instance, "get_fieldname_display"))
|
| 61 |
+
self.assertFalse(hasattr(instance, "get_modelname_display"))
|
| 62 |
+
|
| 63 |
+
def test_field_verbose_name(self):
|
| 64 |
+
m = VerboseNameField
|
| 65 |
+
for i in range(1, 22):
|
| 66 |
+
self.assertEqual(
|
| 67 |
+
m._meta.get_field("field%d" % i).verbose_name, "verbose field%d" % i
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
self.assertEqual(m._meta.get_field("id").verbose_name, "verbose pk")
|
| 71 |
+
|
| 72 |
+
def test_choices_form_class(self):
|
| 73 |
+
"""Can supply a custom choices form class to Field.formfield()"""
|
| 74 |
+
choices = [("a", "a")]
|
| 75 |
+
field = models.CharField(choices=choices)
|
| 76 |
+
klass = forms.TypedMultipleChoiceField
|
| 77 |
+
self.assertIsInstance(field.formfield(choices_form_class=klass), klass)
|
| 78 |
+
|
| 79 |
+
def test_formfield_disabled(self):
|
| 80 |
+
"""Field.formfield() sets disabled for fields with choices."""
|
| 81 |
+
field = models.CharField(choices=[("a", "b")])
|
| 82 |
+
form_field = field.formfield(disabled=True)
|
| 83 |
+
self.assertIs(form_field.disabled, True)
|
| 84 |
+
|
| 85 |
+
def test_field_str(self):
|
| 86 |
+
f = models.Field()
|
| 87 |
+
self.assertEqual(str(f), "<django.db.models.fields.Field>")
|
| 88 |
+
f = Foo._meta.get_field("a")
|
| 89 |
+
self.assertEqual(str(f), "model_fields.Foo.a")
|
| 90 |
+
|
| 91 |
+
def test_field_ordering(self):
|
| 92 |
+
"""Fields are ordered based on their creation."""
|
| 93 |
+
f1 = models.Field()
|
| 94 |
+
f2 = models.Field(auto_created=True)
|
| 95 |
+
f3 = models.Field()
|
| 96 |
+
self.assertLess(f2, f1)
|
| 97 |
+
self.assertGreater(f3, f1)
|
| 98 |
+
self.assertIsNotNone(f1)
|
| 99 |
+
self.assertNotIn(f2, (None, 1, ""))
|
| 100 |
+
|
| 101 |
+
def test_field_instance_is_picklable(self):
|
| 102 |
+
"""Field instances can be pickled."""
|
| 103 |
+
field = models.Field(max_length=100, default="a string")
|
| 104 |
+
# Must be picklable with this cached property populated (#28188).
|
| 105 |
+
field._get_default
|
| 106 |
+
pickle.dumps(field)
|
| 107 |
+
|
| 108 |
+
def test_deconstruct_nested_field(self):
|
| 109 |
+
"""deconstruct() uses __qualname__ for nested class support."""
|
| 110 |
+
name, path, args, kwargs = Nested.Field().deconstruct()
|
| 111 |
+
self.assertEqual(path, "model_fields.tests.Nested.Field")
|
| 112 |
+
|
| 113 |
+
def test_abstract_inherited_fields(self):
|
| 114 |
+
"""Field instances from abstract models are not equal."""
|
| 115 |
+
|
| 116 |
+
class AbstractModel(models.Model):
|
| 117 |
+
field = models.IntegerField()
|
| 118 |
+
|
| 119 |
+
class Meta:
|
| 120 |
+
abstract = True
|
| 121 |
+
|
| 122 |
+
class InheritAbstractModel1(AbstractModel):
|
| 123 |
+
pass
|
| 124 |
+
|
| 125 |
+
class InheritAbstractModel2(AbstractModel):
|
| 126 |
+
pass
|
| 127 |
+
|
| 128 |
+
abstract_model_field = AbstractModel._meta.get_field("field")
|
| 129 |
+
inherit1_model_field = InheritAbstractModel1._meta.get_field("field")
|
| 130 |
+
inherit2_model_field = InheritAbstractModel2._meta.get_field("field")
|
| 131 |
+
|
| 132 |
+
self.assertNotEqual(abstract_model_field, inherit1_model_field)
|
| 133 |
+
self.assertNotEqual(abstract_model_field, inherit2_model_field)
|
| 134 |
+
self.assertNotEqual(inherit1_model_field, inherit2_model_field)
|
| 135 |
+
|
| 136 |
+
self.assertLess(abstract_model_field, inherit1_model_field)
|
| 137 |
+
self.assertLess(abstract_model_field, inherit2_model_field)
|
| 138 |
+
self.assertLess(inherit1_model_field, inherit2_model_field)
|
| 139 |
+
|
| 140 |
+
def test_hash_immutability(self):
|
| 141 |
+
field = models.IntegerField()
|
| 142 |
+
field_hash = hash(field)
|
| 143 |
+
|
| 144 |
+
class MyModel(models.Model):
|
| 145 |
+
rank = field
|
| 146 |
+
|
| 147 |
+
self.assertEqual(field_hash, hash(field))
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class ChoicesTests(SimpleTestCase):
|
| 151 |
+
@classmethod
|
| 152 |
+
def setUpClass(cls):
|
| 153 |
+
super().setUpClass()
|
| 154 |
+
cls.no_choices = Choiceful._meta.get_field("no_choices")
|
| 155 |
+
cls.empty_choices = Choiceful._meta.get_field("empty_choices")
|
| 156 |
+
cls.empty_choices_bool = Choiceful._meta.get_field("empty_choices_bool")
|
| 157 |
+
cls.empty_choices_text = Choiceful._meta.get_field("empty_choices_text")
|
| 158 |
+
cls.with_choices = Choiceful._meta.get_field("with_choices")
|
| 159 |
+
cls.choices_from_enum = Choiceful._meta.get_field("choices_from_enum")
|
| 160 |
+
|
| 161 |
+
def test_choices(self):
|
| 162 |
+
self.assertIsNone(self.no_choices.choices)
|
| 163 |
+
self.assertEqual(self.empty_choices.choices, ())
|
| 164 |
+
self.assertEqual(self.with_choices.choices, [(1, "A")])
|
| 165 |
+
|
| 166 |
+
def test_flatchoices(self):
|
| 167 |
+
self.assertEqual(self.no_choices.flatchoices, [])
|
| 168 |
+
self.assertEqual(self.empty_choices.flatchoices, [])
|
| 169 |
+
self.assertEqual(self.with_choices.flatchoices, [(1, "A")])
|
| 170 |
+
|
| 171 |
+
def test_check(self):
|
| 172 |
+
self.assertEqual(Choiceful.check(), [])
|
| 173 |
+
|
| 174 |
+
def test_invalid_choice(self):
|
| 175 |
+
model_instance = None # Actual model instance not needed.
|
| 176 |
+
self.no_choices.validate(0, model_instance)
|
| 177 |
+
msg = "['Value 99 is not a valid choice.']"
|
| 178 |
+
with self.assertRaisesMessage(ValidationError, msg):
|
| 179 |
+
self.empty_choices.validate(99, model_instance)
|
| 180 |
+
with self.assertRaisesMessage(ValidationError, msg):
|
| 181 |
+
self.with_choices.validate(99, model_instance)
|
| 182 |
+
|
| 183 |
+
def test_formfield(self):
|
| 184 |
+
no_choices_formfield = self.no_choices.formfield()
|
| 185 |
+
self.assertIsInstance(no_choices_formfield, forms.IntegerField)
|
| 186 |
+
fields = (
|
| 187 |
+
self.empty_choices,
|
| 188 |
+
self.with_choices,
|
| 189 |
+
self.empty_choices_bool,
|
| 190 |
+
self.empty_choices_text,
|
| 191 |
+
)
|
| 192 |
+
for field in fields:
|
| 193 |
+
with self.subTest(field=field):
|
| 194 |
+
self.assertIsInstance(field.formfield(), forms.ChoiceField)
|
| 195 |
+
|
| 196 |
+
def test_choices_from_enum(self):
|
| 197 |
+
# Choices class was transparently resolved when given as argument.
|
| 198 |
+
self.assertEqual(self.choices_from_enum.choices, Choiceful.Suit.choices)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class GetFieldDisplayTests(SimpleTestCase):
|
| 202 |
+
def test_choices_and_field_display(self):
|
| 203 |
+
"""
|
| 204 |
+
get_choices() interacts with get_FIELD_display() to return the expected
|
| 205 |
+
values.
|
| 206 |
+
"""
|
| 207 |
+
self.assertEqual(Whiz(c=1).get_c_display(), "First") # A nested value
|
| 208 |
+
self.assertEqual(Whiz(c=0).get_c_display(), "Other") # A top level value
|
| 209 |
+
self.assertEqual(Whiz(c=9).get_c_display(), 9) # Invalid value
|
| 210 |
+
self.assertIsNone(Whiz(c=None).get_c_display()) # Blank value
|
| 211 |
+
self.assertEqual(Whiz(c="").get_c_display(), "") # Empty value
|
| 212 |
+
self.assertEqual(WhizDelayed(c=0).get_c_display(), "Other") # Delayed choices
|
| 213 |
+
|
| 214 |
+
def test_get_FIELD_display_translated(self):
|
| 215 |
+
"""A translated display value is coerced to str."""
|
| 216 |
+
val = Whiz(c=5).get_c_display()
|
| 217 |
+
self.assertIsInstance(val, str)
|
| 218 |
+
self.assertEqual(val, "translated")
|
| 219 |
+
|
| 220 |
+
def test_overriding_FIELD_display(self):
|
| 221 |
+
class FooBar(models.Model):
|
| 222 |
+
foo_bar = models.IntegerField(choices=[(1, "foo"), (2, "bar")])
|
| 223 |
+
|
| 224 |
+
def get_foo_bar_display(self):
|
| 225 |
+
return "something"
|
| 226 |
+
|
| 227 |
+
f = FooBar(foo_bar=1)
|
| 228 |
+
self.assertEqual(f.get_foo_bar_display(), "something")
|
| 229 |
+
|
| 230 |
+
def test_overriding_inherited_FIELD_display(self):
|
| 231 |
+
class Base(models.Model):
|
| 232 |
+
foo = models.CharField(max_length=254, choices=[("A", "Base A")])
|
| 233 |
+
|
| 234 |
+
class Meta:
|
| 235 |
+
abstract = True
|
| 236 |
+
|
| 237 |
+
class Child(Base):
|
| 238 |
+
foo = models.CharField(
|
| 239 |
+
max_length=254, choices=[("A", "Child A"), ("B", "Child B")]
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
self.assertEqual(Child(foo="A").get_foo_display(), "Child A")
|
| 243 |
+
self.assertEqual(Child(foo="B").get_foo_display(), "Child B")
|
| 244 |
+
|
| 245 |
+
def test_iterator_choices(self):
|
| 246 |
+
"""
|
| 247 |
+
get_choices() works with Iterators.
|
| 248 |
+
"""
|
| 249 |
+
self.assertEqual(WhizIter(c=1).c, 1) # A nested value
|
| 250 |
+
self.assertEqual(WhizIter(c=9).c, 9) # Invalid value
|
| 251 |
+
self.assertIsNone(WhizIter(c=None).c) # Blank value
|
| 252 |
+
self.assertEqual(WhizIter(c="").c, "") # Empty value
|
| 253 |
+
|
| 254 |
+
def test_empty_iterator_choices(self):
|
| 255 |
+
"""
|
| 256 |
+
get_choices() works with empty iterators.
|
| 257 |
+
"""
|
| 258 |
+
self.assertEqual(WhizIterEmpty(c="a").c, "a") # A nested value
|
| 259 |
+
self.assertEqual(WhizIterEmpty(c="b").c, "b") # Invalid value
|
| 260 |
+
self.assertIsNone(WhizIterEmpty(c=None).c) # Blank value
|
| 261 |
+
self.assertEqual(WhizIterEmpty(c="").c, "") # Empty value
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
class GetChoicesTests(SimpleTestCase):
|
| 265 |
+
def test_empty_choices(self):
|
| 266 |
+
choices = []
|
| 267 |
+
f = models.CharField(choices=choices)
|
| 268 |
+
self.assertEqual(f.get_choices(include_blank=False), choices)
|
| 269 |
+
|
| 270 |
+
def test_blank_in_choices(self):
|
| 271 |
+
choices = [("", "<><>"), ("a", "A")]
|
| 272 |
+
f = models.CharField(choices=choices)
|
| 273 |
+
self.assertEqual(f.get_choices(include_blank=True), choices)
|
| 274 |
+
|
| 275 |
+
def test_blank_in_grouped_choices(self):
|
| 276 |
+
choices = [
|
| 277 |
+
("f", "Foo"),
|
| 278 |
+
("b", "Bar"),
|
| 279 |
+
(
|
| 280 |
+
"Group",
|
| 281 |
+
(
|
| 282 |
+
("", "No Preference"),
|
| 283 |
+
("fg", "Foo"),
|
| 284 |
+
("bg", "Bar"),
|
| 285 |
+
),
|
| 286 |
+
),
|
| 287 |
+
]
|
| 288 |
+
f = models.CharField(choices=choices)
|
| 289 |
+
self.assertEqual(f.get_choices(include_blank=True), choices)
|
| 290 |
+
|
| 291 |
+
def test_lazy_strings_not_evaluated(self):
|
| 292 |
+
lazy_func = lazy(lambda x: 0 / 0, int) # raises ZeroDivisionError if evaluated.
|
| 293 |
+
f = models.CharField(choices=[(lazy_func("group"), (("a", "A"), ("b", "B")))])
|
| 294 |
+
self.assertEqual(f.get_choices(include_blank=True)[0], ("", "---------"))
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
class GetChoicesOrderingTests(TestCase):
|
| 298 |
+
@classmethod
|
| 299 |
+
def setUpTestData(cls):
|
| 300 |
+
cls.foo1 = Foo.objects.create(a="a", d="12.35")
|
| 301 |
+
cls.foo2 = Foo.objects.create(a="b", d="12.34")
|
| 302 |
+
cls.bar1 = Bar.objects.create(a=cls.foo1, b="b")
|
| 303 |
+
cls.bar2 = Bar.objects.create(a=cls.foo2, b="a")
|
| 304 |
+
cls.field = Bar._meta.get_field("a")
|
| 305 |
+
|
| 306 |
+
def assertChoicesEqual(self, choices, objs):
|
| 307 |
+
self.assertEqual(choices, [(obj.pk, str(obj)) for obj in objs])
|
| 308 |
+
|
| 309 |
+
def test_get_choices(self):
|
| 310 |
+
self.assertChoicesEqual(
|
| 311 |
+
self.field.get_choices(include_blank=False, ordering=("a",)),
|
| 312 |
+
[self.foo1, self.foo2],
|
| 313 |
+
)
|
| 314 |
+
self.assertChoicesEqual(
|
| 315 |
+
self.field.get_choices(include_blank=False, ordering=("-a",)),
|
| 316 |
+
[self.foo2, self.foo1],
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
def test_get_choices_default_ordering(self):
|
| 320 |
+
self.addCleanup(setattr, Foo._meta, "ordering", Foo._meta.ordering)
|
| 321 |
+
Foo._meta.ordering = ("d",)
|
| 322 |
+
self.assertChoicesEqual(
|
| 323 |
+
self.field.get_choices(include_blank=False), [self.foo2, self.foo1]
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
def test_get_choices_reverse_related_field(self):
|
| 327 |
+
self.assertChoicesEqual(
|
| 328 |
+
self.field.remote_field.get_choices(include_blank=False, ordering=("a",)),
|
| 329 |
+
[self.bar1, self.bar2],
|
| 330 |
+
)
|
| 331 |
+
self.assertChoicesEqual(
|
| 332 |
+
self.field.remote_field.get_choices(include_blank=False, ordering=("-a",)),
|
| 333 |
+
[self.bar2, self.bar1],
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
def test_get_choices_reverse_related_field_default_ordering(self):
|
| 337 |
+
self.addCleanup(setattr, Bar._meta, "ordering", Bar._meta.ordering)
|
| 338 |
+
Bar._meta.ordering = ("b",)
|
| 339 |
+
self.assertChoicesEqual(
|
| 340 |
+
self.field.remote_field.get_choices(include_blank=False),
|
| 341 |
+
[self.bar2, self.bar1],
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class GetChoicesLimitChoicesToTests(TestCase):
|
| 346 |
+
@classmethod
|
| 347 |
+
def setUpTestData(cls):
|
| 348 |
+
cls.foo1 = Foo.objects.create(a="a", d="12.34")
|
| 349 |
+
cls.foo2 = Foo.objects.create(a="b", d="12.34")
|
| 350 |
+
cls.bar1 = Bar.objects.create(a=cls.foo1, b="b")
|
| 351 |
+
cls.bar2 = Bar.objects.create(a=cls.foo2, b="a")
|
| 352 |
+
cls.field = Bar._meta.get_field("a")
|
| 353 |
+
|
| 354 |
+
def assertChoicesEqual(self, choices, objs):
|
| 355 |
+
self.assertCountEqual(choices, [(obj.pk, str(obj)) for obj in objs])
|
| 356 |
+
|
| 357 |
+
def test_get_choices(self):
|
| 358 |
+
self.assertChoicesEqual(
|
| 359 |
+
self.field.get_choices(include_blank=False, limit_choices_to={"a": "a"}),
|
| 360 |
+
[self.foo1],
|
| 361 |
+
)
|
| 362 |
+
self.assertChoicesEqual(
|
| 363 |
+
self.field.get_choices(include_blank=False, limit_choices_to={}),
|
| 364 |
+
[self.foo1, self.foo2],
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
def test_get_choices_reverse_related_field(self):
|
| 368 |
+
field = self.field.remote_field
|
| 369 |
+
self.assertChoicesEqual(
|
| 370 |
+
field.get_choices(include_blank=False, limit_choices_to={"b": "b"}),
|
| 371 |
+
[self.bar1],
|
| 372 |
+
)
|
| 373 |
+
self.assertChoicesEqual(
|
| 374 |
+
field.get_choices(include_blank=False, limit_choices_to={}),
|
| 375 |
+
[self.bar1, self.bar2],
|
| 376 |
+
)
|
testbed/django__django/tests/model_forms/__init__.py
ADDED
|
File without changes
|
testbed/django__django/tests/model_forms/models.py
ADDED
|
@@ -0,0 +1,523 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
| 6 |
+
from django.core import validators
|
| 7 |
+
from django.core.exceptions import ValidationError
|
| 8 |
+
from django.core.files.storage import FileSystemStorage
|
| 9 |
+
from django.db import models
|
| 10 |
+
|
| 11 |
+
temp_storage_dir = tempfile.mkdtemp()
|
| 12 |
+
temp_storage = FileSystemStorage(temp_storage_dir)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class Person(models.Model):
|
| 16 |
+
name = models.CharField(max_length=100)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Category(models.Model):
|
| 20 |
+
name = models.CharField(max_length=20)
|
| 21 |
+
slug = models.SlugField(max_length=20)
|
| 22 |
+
url = models.CharField("The URL", max_length=40)
|
| 23 |
+
|
| 24 |
+
class Meta:
|
| 25 |
+
ordering = ("pk",)
|
| 26 |
+
|
| 27 |
+
def __str__(self):
|
| 28 |
+
return self.name
|
| 29 |
+
|
| 30 |
+
def __repr__(self):
|
| 31 |
+
return self.__str__()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class WriterManager(models.Manager):
|
| 35 |
+
def get_queryset(self):
|
| 36 |
+
qs = super().get_queryset()
|
| 37 |
+
return qs.filter(archived=False)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class Writer(models.Model):
|
| 41 |
+
name = models.CharField(max_length=50, help_text="Use both first and last names.")
|
| 42 |
+
archived = models.BooleanField(default=False, editable=False)
|
| 43 |
+
|
| 44 |
+
objects = WriterManager()
|
| 45 |
+
|
| 46 |
+
class Meta:
|
| 47 |
+
ordering = ("name",)
|
| 48 |
+
|
| 49 |
+
def __str__(self):
|
| 50 |
+
return self.name
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class Article(models.Model):
|
| 54 |
+
ARTICLE_STATUS = (
|
| 55 |
+
(1, "Draft"),
|
| 56 |
+
(2, "Pending"),
|
| 57 |
+
(3, "Live"),
|
| 58 |
+
)
|
| 59 |
+
headline = models.CharField(max_length=50)
|
| 60 |
+
slug = models.SlugField()
|
| 61 |
+
pub_date = models.DateField()
|
| 62 |
+
created = models.DateField(editable=False)
|
| 63 |
+
writer = models.ForeignKey(Writer, models.CASCADE)
|
| 64 |
+
article = models.TextField()
|
| 65 |
+
categories = models.ManyToManyField(Category, blank=True)
|
| 66 |
+
status = models.PositiveIntegerField(choices=ARTICLE_STATUS, blank=True, null=True)
|
| 67 |
+
|
| 68 |
+
def save(self, *args, **kwargs):
|
| 69 |
+
if not self.id:
|
| 70 |
+
self.created = datetime.date.today()
|
| 71 |
+
return super().save(*args, **kwargs)
|
| 72 |
+
|
| 73 |
+
def __str__(self):
|
| 74 |
+
return self.headline
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class ImprovedArticle(models.Model):
|
| 78 |
+
article = models.OneToOneField(Article, models.CASCADE)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class ImprovedArticleWithParentLink(models.Model):
|
| 82 |
+
article = models.OneToOneField(Article, models.CASCADE, parent_link=True)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class BetterWriter(Writer):
|
| 86 |
+
score = models.IntegerField()
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class Publication(models.Model):
|
| 90 |
+
title = models.CharField(max_length=30)
|
| 91 |
+
date_published = models.DateField()
|
| 92 |
+
|
| 93 |
+
def __str__(self):
|
| 94 |
+
return self.title
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def default_mode():
|
| 98 |
+
return "di"
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def default_category():
|
| 102 |
+
return 3
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class PublicationDefaults(models.Model):
|
| 106 |
+
MODE_CHOICES = (("di", "direct"), ("de", "delayed"))
|
| 107 |
+
CATEGORY_CHOICES = ((1, "Games"), (2, "Comics"), (3, "Novel"))
|
| 108 |
+
title = models.CharField(max_length=30)
|
| 109 |
+
date_published = models.DateField(default=datetime.date.today)
|
| 110 |
+
datetime_published = models.DateTimeField(default=datetime.datetime(2000, 1, 1))
|
| 111 |
+
mode = models.CharField(max_length=2, choices=MODE_CHOICES, default=default_mode)
|
| 112 |
+
category = models.IntegerField(choices=CATEGORY_CHOICES, default=default_category)
|
| 113 |
+
active = models.BooleanField(default=True)
|
| 114 |
+
file = models.FileField(default="default.txt")
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class Author(models.Model):
|
| 118 |
+
publication = models.OneToOneField(
|
| 119 |
+
Publication, models.SET_NULL, null=True, blank=True
|
| 120 |
+
)
|
| 121 |
+
full_name = models.CharField(max_length=255)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class Author1(models.Model):
|
| 125 |
+
publication = models.OneToOneField(Publication, models.CASCADE, null=False)
|
| 126 |
+
full_name = models.CharField(max_length=255)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class WriterProfile(models.Model):
|
| 130 |
+
writer = models.OneToOneField(Writer, models.CASCADE, primary_key=True)
|
| 131 |
+
age = models.PositiveIntegerField()
|
| 132 |
+
|
| 133 |
+
def __str__(self):
|
| 134 |
+
return "%s is %s" % (self.writer, self.age)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class Document(models.Model):
|
| 138 |
+
myfile = models.FileField(upload_to="unused", blank=True)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class TextFile(models.Model):
|
| 142 |
+
description = models.CharField(max_length=20)
|
| 143 |
+
file = models.FileField(storage=temp_storage, upload_to="tests", max_length=15)
|
| 144 |
+
|
| 145 |
+
def __str__(self):
|
| 146 |
+
return self.description
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class CustomFileField(models.FileField):
|
| 150 |
+
def save_form_data(self, instance, data):
|
| 151 |
+
been_here = getattr(self, "been_saved", False)
|
| 152 |
+
assert not been_here, "save_form_data called more than once"
|
| 153 |
+
setattr(self, "been_saved", True)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
class CustomFF(models.Model):
|
| 157 |
+
f = CustomFileField(upload_to="unused", blank=True)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class FilePathModel(models.Model):
|
| 161 |
+
path = models.FilePathField(
|
| 162 |
+
path=os.path.dirname(__file__), match="models.py", blank=True
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
from PIL import Image # NOQA: detect if Pillow is installed
|
| 168 |
+
|
| 169 |
+
test_images = True
|
| 170 |
+
|
| 171 |
+
class ImageFile(models.Model):
|
| 172 |
+
def custom_upload_path(self, filename):
|
| 173 |
+
path = self.path or "tests"
|
| 174 |
+
return "%s/%s" % (path, filename)
|
| 175 |
+
|
| 176 |
+
description = models.CharField(max_length=20)
|
| 177 |
+
|
| 178 |
+
# Deliberately put the image field *after* the width/height fields to
|
| 179 |
+
# trigger the bug in #10404 with width/height not getting assigned.
|
| 180 |
+
width = models.IntegerField(editable=False)
|
| 181 |
+
height = models.IntegerField(editable=False)
|
| 182 |
+
image = models.ImageField(
|
| 183 |
+
storage=temp_storage,
|
| 184 |
+
upload_to=custom_upload_path,
|
| 185 |
+
width_field="width",
|
| 186 |
+
height_field="height",
|
| 187 |
+
)
|
| 188 |
+
path = models.CharField(max_length=16, blank=True, default="")
|
| 189 |
+
|
| 190 |
+
def __str__(self):
|
| 191 |
+
return self.description
|
| 192 |
+
|
| 193 |
+
class OptionalImageFile(models.Model):
|
| 194 |
+
def custom_upload_path(self, filename):
|
| 195 |
+
path = self.path or "tests"
|
| 196 |
+
return "%s/%s" % (path, filename)
|
| 197 |
+
|
| 198 |
+
description = models.CharField(max_length=20)
|
| 199 |
+
image = models.ImageField(
|
| 200 |
+
storage=temp_storage,
|
| 201 |
+
upload_to=custom_upload_path,
|
| 202 |
+
width_field="width",
|
| 203 |
+
height_field="height",
|
| 204 |
+
blank=True,
|
| 205 |
+
null=True,
|
| 206 |
+
)
|
| 207 |
+
width = models.IntegerField(editable=False, null=True)
|
| 208 |
+
height = models.IntegerField(editable=False, null=True)
|
| 209 |
+
path = models.CharField(max_length=16, blank=True, default="")
|
| 210 |
+
|
| 211 |
+
def __str__(self):
|
| 212 |
+
return self.description
|
| 213 |
+
|
| 214 |
+
class NoExtensionImageFile(models.Model):
|
| 215 |
+
def upload_to(self, filename):
|
| 216 |
+
return "tests/no_extension"
|
| 217 |
+
|
| 218 |
+
description = models.CharField(max_length=20)
|
| 219 |
+
image = models.ImageField(storage=temp_storage, upload_to=upload_to)
|
| 220 |
+
|
| 221 |
+
def __str__(self):
|
| 222 |
+
return self.description
|
| 223 |
+
|
| 224 |
+
except ImportError:
|
| 225 |
+
test_images = False
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
class Homepage(models.Model):
|
| 229 |
+
url = models.URLField()
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class Product(models.Model):
|
| 233 |
+
slug = models.SlugField(unique=True)
|
| 234 |
+
|
| 235 |
+
def __str__(self):
|
| 236 |
+
return self.slug
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class Price(models.Model):
|
| 240 |
+
price = models.DecimalField(max_digits=10, decimal_places=2)
|
| 241 |
+
quantity = models.PositiveIntegerField()
|
| 242 |
+
|
| 243 |
+
class Meta:
|
| 244 |
+
unique_together = (("price", "quantity"),)
|
| 245 |
+
|
| 246 |
+
def __str__(self):
|
| 247 |
+
return "%s for %s" % (self.quantity, self.price)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
class Triple(models.Model):
|
| 251 |
+
left = models.IntegerField()
|
| 252 |
+
middle = models.IntegerField()
|
| 253 |
+
right = models.IntegerField()
|
| 254 |
+
|
| 255 |
+
class Meta:
|
| 256 |
+
unique_together = (("left", "middle"), ("middle", "right"))
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
class ArticleStatus(models.Model):
|
| 260 |
+
ARTICLE_STATUS_CHAR = (
|
| 261 |
+
("d", "Draft"),
|
| 262 |
+
("p", "Pending"),
|
| 263 |
+
("l", "Live"),
|
| 264 |
+
)
|
| 265 |
+
status = models.CharField(
|
| 266 |
+
max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
class Inventory(models.Model):
|
| 271 |
+
barcode = models.PositiveIntegerField(unique=True)
|
| 272 |
+
parent = models.ForeignKey(
|
| 273 |
+
"self", models.SET_NULL, to_field="barcode", blank=True, null=True
|
| 274 |
+
)
|
| 275 |
+
name = models.CharField(blank=False, max_length=20)
|
| 276 |
+
|
| 277 |
+
class Meta:
|
| 278 |
+
ordering = ("name",)
|
| 279 |
+
|
| 280 |
+
def __str__(self):
|
| 281 |
+
return self.name
|
| 282 |
+
|
| 283 |
+
def __repr__(self):
|
| 284 |
+
return self.__str__()
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class Book(models.Model):
|
| 288 |
+
title = models.CharField(max_length=40)
|
| 289 |
+
author = models.ForeignKey(Writer, models.SET_NULL, blank=True, null=True)
|
| 290 |
+
special_id = models.IntegerField(blank=True, null=True, unique=True)
|
| 291 |
+
|
| 292 |
+
class Meta:
|
| 293 |
+
unique_together = ("title", "author")
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
class BookXtra(models.Model):
|
| 297 |
+
isbn = models.CharField(max_length=16, unique=True)
|
| 298 |
+
suffix1 = models.IntegerField(blank=True, default=0)
|
| 299 |
+
suffix2 = models.IntegerField(blank=True, default=0)
|
| 300 |
+
|
| 301 |
+
class Meta:
|
| 302 |
+
unique_together = ("suffix1", "suffix2")
|
| 303 |
+
abstract = True
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
class DerivedBook(Book, BookXtra):
|
| 307 |
+
pass
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
class ExplicitPK(models.Model):
|
| 311 |
+
key = models.CharField(max_length=20, primary_key=True)
|
| 312 |
+
desc = models.CharField(max_length=20, blank=True, unique=True)
|
| 313 |
+
|
| 314 |
+
class Meta:
|
| 315 |
+
unique_together = ("key", "desc")
|
| 316 |
+
|
| 317 |
+
def __str__(self):
|
| 318 |
+
return self.key
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
class Post(models.Model):
|
| 322 |
+
title = models.CharField(max_length=50, unique_for_date="posted", blank=True)
|
| 323 |
+
slug = models.CharField(max_length=50, unique_for_year="posted", blank=True)
|
| 324 |
+
subtitle = models.CharField(max_length=50, unique_for_month="posted", blank=True)
|
| 325 |
+
posted = models.DateField()
|
| 326 |
+
|
| 327 |
+
def __str__(self):
|
| 328 |
+
return self.title
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class DateTimePost(models.Model):
|
| 332 |
+
title = models.CharField(max_length=50, unique_for_date="posted", blank=True)
|
| 333 |
+
slug = models.CharField(max_length=50, unique_for_year="posted", blank=True)
|
| 334 |
+
subtitle = models.CharField(max_length=50, unique_for_month="posted", blank=True)
|
| 335 |
+
posted = models.DateTimeField(editable=False)
|
| 336 |
+
|
| 337 |
+
def __str__(self):
|
| 338 |
+
return self.title
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
class DerivedPost(Post):
|
| 342 |
+
pass
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class BigInt(models.Model):
|
| 346 |
+
biggie = models.BigIntegerField()
|
| 347 |
+
|
| 348 |
+
def __str__(self):
|
| 349 |
+
return str(self.biggie)
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
class MarkupField(models.CharField):
|
| 353 |
+
def __init__(self, *args, **kwargs):
|
| 354 |
+
kwargs["max_length"] = 20
|
| 355 |
+
super().__init__(*args, **kwargs)
|
| 356 |
+
|
| 357 |
+
def formfield(self, **kwargs):
|
| 358 |
+
# don't allow this field to be used in form (real use-case might be
|
| 359 |
+
# that you know the markup will always be X, but it is among an app
|
| 360 |
+
# that allows the user to say it could be something else)
|
| 361 |
+
# regressed at r10062
|
| 362 |
+
return None
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
class CustomFieldForExclusionModel(models.Model):
|
| 366 |
+
name = models.CharField(max_length=10)
|
| 367 |
+
markup = MarkupField()
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
class FlexibleDatePost(models.Model):
|
| 371 |
+
title = models.CharField(max_length=50, unique_for_date="posted", blank=True)
|
| 372 |
+
slug = models.CharField(max_length=50, unique_for_year="posted", blank=True)
|
| 373 |
+
subtitle = models.CharField(max_length=50, unique_for_month="posted", blank=True)
|
| 374 |
+
posted = models.DateField(blank=True, null=True)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
class Colour(models.Model):
|
| 378 |
+
name = models.CharField(max_length=50)
|
| 379 |
+
|
| 380 |
+
def __iter__(self):
|
| 381 |
+
yield from range(5)
|
| 382 |
+
|
| 383 |
+
def __str__(self):
|
| 384 |
+
return self.name
|
| 385 |
+
|
| 386 |
+
|
| 387 |
+
class ColourfulItem(models.Model):
|
| 388 |
+
name = models.CharField(max_length=50)
|
| 389 |
+
colours = models.ManyToManyField(Colour)
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
class CustomErrorMessage(models.Model):
|
| 393 |
+
name1 = models.CharField(
|
| 394 |
+
max_length=50,
|
| 395 |
+
validators=[validators.validate_slug],
|
| 396 |
+
error_messages={"invalid": "Model custom error message."},
|
| 397 |
+
)
|
| 398 |
+
name2 = models.CharField(
|
| 399 |
+
max_length=50,
|
| 400 |
+
validators=[validators.validate_slug],
|
| 401 |
+
error_messages={"invalid": "Model custom error message."},
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
def clean(self):
|
| 405 |
+
if self.name1 == "FORBIDDEN_VALUE":
|
| 406 |
+
raise ValidationError(
|
| 407 |
+
{"name1": [ValidationError("Model.clean() error messages.")]}
|
| 408 |
+
)
|
| 409 |
+
elif self.name1 == "FORBIDDEN_VALUE2":
|
| 410 |
+
raise ValidationError(
|
| 411 |
+
{"name1": "Model.clean() error messages (simpler syntax)."}
|
| 412 |
+
)
|
| 413 |
+
elif self.name1 == "GLOBAL_ERROR":
|
| 414 |
+
raise ValidationError("Global error message.")
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def today_callable_dict():
|
| 418 |
+
return {"last_action__gte": datetime.datetime.today()}
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
def today_callable_q():
|
| 422 |
+
return models.Q(last_action__gte=datetime.datetime.today())
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
class Character(models.Model):
|
| 426 |
+
username = models.CharField(max_length=100)
|
| 427 |
+
last_action = models.DateTimeField()
|
| 428 |
+
|
| 429 |
+
def __str__(self):
|
| 430 |
+
return self.username
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
class StumpJoke(models.Model):
|
| 434 |
+
most_recently_fooled = models.ForeignKey(
|
| 435 |
+
Character,
|
| 436 |
+
models.CASCADE,
|
| 437 |
+
limit_choices_to=today_callable_dict,
|
| 438 |
+
related_name="jokes",
|
| 439 |
+
)
|
| 440 |
+
has_fooled_today = models.ManyToManyField(
|
| 441 |
+
Character,
|
| 442 |
+
limit_choices_to=today_callable_q,
|
| 443 |
+
related_name="jokes_today",
|
| 444 |
+
)
|
| 445 |
+
funny = models.BooleanField(default=False)
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
# Model for #13776
|
| 449 |
+
class Student(models.Model):
|
| 450 |
+
character = models.ForeignKey(Character, models.CASCADE)
|
| 451 |
+
study = models.CharField(max_length=30)
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
# Model for #639
|
| 455 |
+
class Photo(models.Model):
|
| 456 |
+
title = models.CharField(max_length=30)
|
| 457 |
+
image = models.FileField(storage=temp_storage, upload_to="tests")
|
| 458 |
+
|
| 459 |
+
# Support code for the tests; this keeps track of how many times save()
|
| 460 |
+
# gets called on each instance.
|
| 461 |
+
def __init__(self, *args, **kwargs):
|
| 462 |
+
super().__init__(*args, **kwargs)
|
| 463 |
+
self._savecount = 0
|
| 464 |
+
|
| 465 |
+
def save(self, force_insert=False, force_update=False):
|
| 466 |
+
super().save(force_insert, force_update)
|
| 467 |
+
self._savecount += 1
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
class UUIDPK(models.Model):
|
| 471 |
+
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 472 |
+
name = models.CharField(max_length=30)
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
# Models for #24706
|
| 476 |
+
class StrictAssignmentFieldSpecific(models.Model):
|
| 477 |
+
title = models.CharField(max_length=30)
|
| 478 |
+
_should_error = False
|
| 479 |
+
|
| 480 |
+
def __setattr__(self, key, value):
|
| 481 |
+
if self._should_error is True:
|
| 482 |
+
raise ValidationError(message={key: "Cannot set attribute"}, code="invalid")
|
| 483 |
+
super().__setattr__(key, value)
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
class StrictAssignmentAll(models.Model):
|
| 487 |
+
title = models.CharField(max_length=30)
|
| 488 |
+
_should_error = False
|
| 489 |
+
|
| 490 |
+
def __setattr__(self, key, value):
|
| 491 |
+
if self._should_error is True:
|
| 492 |
+
raise ValidationError(message="Cannot set attribute", code="invalid")
|
| 493 |
+
super().__setattr__(key, value)
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
# A model with ForeignKey(blank=False, null=True)
|
| 497 |
+
class Award(models.Model):
|
| 498 |
+
name = models.CharField(max_length=30)
|
| 499 |
+
character = models.ForeignKey(Character, models.SET_NULL, blank=False, null=True)
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
class NullableUniqueCharFieldModel(models.Model):
|
| 503 |
+
codename = models.CharField(max_length=50, blank=True, null=True, unique=True)
|
| 504 |
+
email = models.EmailField(blank=True, null=True)
|
| 505 |
+
slug = models.SlugField(blank=True, null=True)
|
| 506 |
+
url = models.URLField(blank=True, null=True)
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
class Number(models.Model):
|
| 510 |
+
value = models.IntegerField()
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
class NumbersToDice(models.Model):
|
| 514 |
+
number = models.ForeignKey("Number", on_delete=models.CASCADE)
|
| 515 |
+
die = models.ForeignKey("Dice", on_delete=models.CASCADE)
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
class Dice(models.Model):
|
| 519 |
+
numbers = models.ManyToManyField(
|
| 520 |
+
Number,
|
| 521 |
+
through=NumbersToDice,
|
| 522 |
+
limit_choices_to=models.Q(value__gte=1),
|
| 523 |
+
)
|
testbed/django__django/tests/model_forms/test_uuid.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django import forms
|
| 2 |
+
from django.core.exceptions import ValidationError
|
| 3 |
+
from django.test import TestCase
|
| 4 |
+
|
| 5 |
+
from .models import UUIDPK
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class UUIDPKForm(forms.ModelForm):
|
| 9 |
+
class Meta:
|
| 10 |
+
model = UUIDPK
|
| 11 |
+
fields = "__all__"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class ModelFormBaseTest(TestCase):
|
| 15 |
+
def test_create_save_error(self):
|
| 16 |
+
form = UUIDPKForm({})
|
| 17 |
+
self.assertFalse(form.is_valid())
|
| 18 |
+
msg = "The UUIDPK could not be created because the data didn't validate."
|
| 19 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 20 |
+
form.save()
|
| 21 |
+
|
| 22 |
+
def test_update_save_error(self):
|
| 23 |
+
obj = UUIDPK.objects.create(name="foo")
|
| 24 |
+
form = UUIDPKForm({}, instance=obj)
|
| 25 |
+
self.assertFalse(form.is_valid())
|
| 26 |
+
msg = "The UUIDPK could not be changed because the data didn't validate."
|
| 27 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 28 |
+
form.save()
|
| 29 |
+
|
| 30 |
+
def test_model_multiple_choice_field_uuid_pk(self):
|
| 31 |
+
f = forms.ModelMultipleChoiceField(UUIDPK.objects.all())
|
| 32 |
+
with self.assertRaisesMessage(
|
| 33 |
+
ValidationError, "“invalid_uuid” is not a valid UUID."
|
| 34 |
+
):
|
| 35 |
+
f.clean(["invalid_uuid"])
|
testbed/django__django/tests/model_forms/tests.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
testbed/django__django/tests/model_formsets/__init__.py
ADDED
|
File without changes
|
testbed/django__django/tests/model_formsets/models.py
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import uuid
|
| 3 |
+
|
| 4 |
+
from django.db import models
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Author(models.Model):
|
| 8 |
+
name = models.CharField(max_length=100)
|
| 9 |
+
|
| 10 |
+
class Meta:
|
| 11 |
+
ordering = ("name",)
|
| 12 |
+
|
| 13 |
+
def __str__(self):
|
| 14 |
+
return self.name
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class BetterAuthor(Author):
|
| 18 |
+
write_speed = models.IntegerField()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Book(models.Model):
|
| 22 |
+
author = models.ForeignKey(Author, models.CASCADE)
|
| 23 |
+
title = models.CharField(max_length=100)
|
| 24 |
+
|
| 25 |
+
class Meta:
|
| 26 |
+
unique_together = (("author", "title"),)
|
| 27 |
+
ordering = ["id"]
|
| 28 |
+
|
| 29 |
+
def __str__(self):
|
| 30 |
+
return self.title
|
| 31 |
+
|
| 32 |
+
def clean(self):
|
| 33 |
+
# Ensure author is always accessible in clean method
|
| 34 |
+
assert self.author.name is not None
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class BookWithCustomPK(models.Model):
|
| 38 |
+
my_pk = models.DecimalField(max_digits=5, decimal_places=0, primary_key=True)
|
| 39 |
+
author = models.ForeignKey(Author, models.CASCADE)
|
| 40 |
+
title = models.CharField(max_length=100)
|
| 41 |
+
|
| 42 |
+
def __str__(self):
|
| 43 |
+
return "%s: %s" % (self.my_pk, self.title)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Editor(models.Model):
|
| 47 |
+
name = models.CharField(max_length=100)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class BookWithOptionalAltEditor(models.Model):
|
| 51 |
+
author = models.ForeignKey(Author, models.CASCADE)
|
| 52 |
+
# Optional secondary author
|
| 53 |
+
alt_editor = models.ForeignKey(Editor, models.SET_NULL, blank=True, null=True)
|
| 54 |
+
title = models.CharField(max_length=100)
|
| 55 |
+
|
| 56 |
+
class Meta:
|
| 57 |
+
unique_together = (("author", "title", "alt_editor"),)
|
| 58 |
+
|
| 59 |
+
def __str__(self):
|
| 60 |
+
return self.title
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class AlternateBook(Book):
|
| 64 |
+
notes = models.CharField(max_length=100)
|
| 65 |
+
|
| 66 |
+
def __str__(self):
|
| 67 |
+
return "%s - %s" % (self.title, self.notes)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class AuthorMeeting(models.Model):
|
| 71 |
+
name = models.CharField(max_length=100)
|
| 72 |
+
authors = models.ManyToManyField(Author)
|
| 73 |
+
created = models.DateField(editable=False)
|
| 74 |
+
|
| 75 |
+
def __str__(self):
|
| 76 |
+
return self.name
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class CustomPrimaryKey(models.Model):
|
| 80 |
+
my_pk = models.CharField(max_length=10, primary_key=True)
|
| 81 |
+
some_field = models.CharField(max_length=100)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# models for inheritance tests.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class Place(models.Model):
|
| 88 |
+
name = models.CharField(max_length=50)
|
| 89 |
+
city = models.CharField(max_length=50)
|
| 90 |
+
|
| 91 |
+
def __str__(self):
|
| 92 |
+
return self.name
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class Owner(models.Model):
|
| 96 |
+
auto_id = models.AutoField(primary_key=True)
|
| 97 |
+
name = models.CharField(max_length=100)
|
| 98 |
+
place = models.ForeignKey(Place, models.CASCADE)
|
| 99 |
+
|
| 100 |
+
def __str__(self):
|
| 101 |
+
return "%s at %s" % (self.name, self.place)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class Location(models.Model):
|
| 105 |
+
place = models.ForeignKey(Place, models.CASCADE, unique=True)
|
| 106 |
+
# this is purely for testing the data doesn't matter here :)
|
| 107 |
+
lat = models.CharField(max_length=100)
|
| 108 |
+
lon = models.CharField(max_length=100)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
class OwnerProfile(models.Model):
|
| 112 |
+
owner = models.OneToOneField(Owner, models.CASCADE, primary_key=True)
|
| 113 |
+
age = models.PositiveIntegerField()
|
| 114 |
+
|
| 115 |
+
def __str__(self):
|
| 116 |
+
return "%s is %d" % (self.owner.name, self.age)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class Restaurant(Place):
|
| 120 |
+
serves_pizza = models.BooleanField(default=False)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class Product(models.Model):
|
| 124 |
+
slug = models.SlugField(unique=True)
|
| 125 |
+
|
| 126 |
+
def __str__(self):
|
| 127 |
+
return self.slug
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
class Price(models.Model):
|
| 131 |
+
price = models.DecimalField(max_digits=10, decimal_places=2)
|
| 132 |
+
quantity = models.PositiveIntegerField()
|
| 133 |
+
|
| 134 |
+
class Meta:
|
| 135 |
+
unique_together = (("price", "quantity"),)
|
| 136 |
+
|
| 137 |
+
def __str__(self):
|
| 138 |
+
return "%s for %s" % (self.quantity, self.price)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class MexicanRestaurant(Restaurant):
|
| 142 |
+
serves_tacos = models.BooleanField(default=False)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class ClassyMexicanRestaurant(MexicanRestaurant):
|
| 146 |
+
the_restaurant = models.OneToOneField(
|
| 147 |
+
MexicanRestaurant, models.CASCADE, parent_link=True, primary_key=True
|
| 148 |
+
)
|
| 149 |
+
tacos_are_yummy = models.BooleanField(default=False)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# models for testing unique_together validation when a fk is involved and
|
| 153 |
+
# using inlineformset_factory.
|
| 154 |
+
class Repository(models.Model):
|
| 155 |
+
name = models.CharField(max_length=25)
|
| 156 |
+
|
| 157 |
+
def __str__(self):
|
| 158 |
+
return self.name
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class Revision(models.Model):
|
| 162 |
+
repository = models.ForeignKey(Repository, models.CASCADE)
|
| 163 |
+
revision = models.CharField(max_length=40)
|
| 164 |
+
|
| 165 |
+
class Meta:
|
| 166 |
+
unique_together = (("repository", "revision"),)
|
| 167 |
+
|
| 168 |
+
def __str__(self):
|
| 169 |
+
return "%s (%s)" % (self.revision, str(self.repository))
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
# models for testing callable defaults (see bug #7975). If you define a model
|
| 173 |
+
# with a callable default value, you cannot rely on the initial value in a
|
| 174 |
+
# form.
|
| 175 |
+
class Person(models.Model):
|
| 176 |
+
name = models.CharField(max_length=128)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
class Membership(models.Model):
|
| 180 |
+
person = models.ForeignKey(Person, models.CASCADE)
|
| 181 |
+
date_joined = models.DateTimeField(default=datetime.datetime.now)
|
| 182 |
+
karma = models.IntegerField()
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
# models for testing a null=True fk to a parent
|
| 186 |
+
class Team(models.Model):
|
| 187 |
+
name = models.CharField(max_length=100)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
class Player(models.Model):
|
| 191 |
+
team = models.ForeignKey(Team, models.SET_NULL, null=True)
|
| 192 |
+
name = models.CharField(max_length=100)
|
| 193 |
+
|
| 194 |
+
def __str__(self):
|
| 195 |
+
return self.name
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
# Models for testing custom ModelForm save methods in formsets and inline formsets
|
| 199 |
+
class Poet(models.Model):
|
| 200 |
+
name = models.CharField(max_length=100)
|
| 201 |
+
|
| 202 |
+
def __str__(self):
|
| 203 |
+
return self.name
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
class Poem(models.Model):
|
| 207 |
+
poet = models.ForeignKey(Poet, models.CASCADE)
|
| 208 |
+
name = models.CharField(max_length=100)
|
| 209 |
+
|
| 210 |
+
def __str__(self):
|
| 211 |
+
return self.name
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class Post(models.Model):
|
| 215 |
+
title = models.CharField(max_length=50, unique_for_date="posted", blank=True)
|
| 216 |
+
slug = models.CharField(max_length=50, unique_for_year="posted", blank=True)
|
| 217 |
+
subtitle = models.CharField(max_length=50, unique_for_month="posted", blank=True)
|
| 218 |
+
posted = models.DateField()
|
| 219 |
+
|
| 220 |
+
def __str__(self):
|
| 221 |
+
return self.title
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
# Models for testing UUID primary keys
|
| 225 |
+
class UUIDPKParent(models.Model):
|
| 226 |
+
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 227 |
+
name = models.CharField(max_length=255)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
class UUIDPKChild(models.Model):
|
| 231 |
+
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 232 |
+
name = models.CharField(max_length=255)
|
| 233 |
+
parent = models.ForeignKey(UUIDPKParent, models.CASCADE)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
class ChildWithEditablePK(models.Model):
|
| 237 |
+
name = models.CharField(max_length=255, primary_key=True)
|
| 238 |
+
parent = models.ForeignKey(UUIDPKParent, models.CASCADE)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
class AutoPKChildOfUUIDPKParent(models.Model):
|
| 242 |
+
name = models.CharField(max_length=255)
|
| 243 |
+
parent = models.ForeignKey(UUIDPKParent, models.CASCADE)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
class AutoPKParent(models.Model):
|
| 247 |
+
name = models.CharField(max_length=255)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
class UUIDPKChildOfAutoPKParent(models.Model):
|
| 251 |
+
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
| 252 |
+
name = models.CharField(max_length=255)
|
| 253 |
+
parent = models.ForeignKey(AutoPKParent, models.CASCADE)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class ParentWithUUIDAlternateKey(models.Model):
|
| 257 |
+
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
|
| 258 |
+
name = models.CharField(max_length=50)
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
class ChildRelatedViaAK(models.Model):
|
| 262 |
+
name = models.CharField(max_length=255)
|
| 263 |
+
parent = models.ForeignKey(
|
| 264 |
+
ParentWithUUIDAlternateKey, models.CASCADE, to_field="uuid"
|
| 265 |
+
)
|
testbed/django__django/tests/model_formsets/test_uuid.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.forms.models import inlineformset_factory
|
| 2 |
+
from django.test import TestCase
|
| 3 |
+
|
| 4 |
+
from .models import (
|
| 5 |
+
AutoPKChildOfUUIDPKParent,
|
| 6 |
+
AutoPKParent,
|
| 7 |
+
ChildRelatedViaAK,
|
| 8 |
+
ChildWithEditablePK,
|
| 9 |
+
ParentWithUUIDAlternateKey,
|
| 10 |
+
UUIDPKChild,
|
| 11 |
+
UUIDPKChildOfAutoPKParent,
|
| 12 |
+
UUIDPKParent,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class InlineFormsetTests(TestCase):
|
| 17 |
+
def test_inlineformset_factory_nulls_default_pks(self):
|
| 18 |
+
"""
|
| 19 |
+
#24377 - If we're adding a new object, a parent's auto-generated pk
|
| 20 |
+
from the model field default should be ignored as it's regenerated on
|
| 21 |
+
the save request.
|
| 22 |
+
|
| 23 |
+
Tests the case where both the parent and child have a UUID primary key.
|
| 24 |
+
"""
|
| 25 |
+
FormSet = inlineformset_factory(UUIDPKParent, UUIDPKChild, fields="__all__")
|
| 26 |
+
formset = FormSet()
|
| 27 |
+
self.assertIsNone(formset.forms[0].fields["parent"].initial)
|
| 28 |
+
|
| 29 |
+
def test_inlineformset_factory_ignores_default_pks_on_submit(self):
|
| 30 |
+
"""
|
| 31 |
+
#24377 - Inlines with a model field default should ignore that default
|
| 32 |
+
value to avoid triggering validation on empty forms.
|
| 33 |
+
"""
|
| 34 |
+
FormSet = inlineformset_factory(UUIDPKParent, UUIDPKChild, fields="__all__")
|
| 35 |
+
formset = FormSet(
|
| 36 |
+
{
|
| 37 |
+
"uuidpkchild_set-TOTAL_FORMS": 3,
|
| 38 |
+
"uuidpkchild_set-INITIAL_FORMS": 0,
|
| 39 |
+
"uuidpkchild_set-MAX_NUM_FORMS": "",
|
| 40 |
+
"uuidpkchild_set-0-name": "Foo",
|
| 41 |
+
"uuidpkchild_set-1-name": "",
|
| 42 |
+
"uuidpkchild_set-2-name": "",
|
| 43 |
+
}
|
| 44 |
+
)
|
| 45 |
+
self.assertTrue(formset.is_valid())
|
| 46 |
+
self.assertIsNone(formset.instance.uuid)
|
| 47 |
+
self.assertIsNone(formset.forms[0].instance.parent_id)
|
| 48 |
+
|
| 49 |
+
def test_inlineformset_factory_nulls_default_pks_uuid_parent_auto_child(self):
|
| 50 |
+
"""
|
| 51 |
+
#24958 - Variant of test_inlineformset_factory_nulls_default_pks for
|
| 52 |
+
the case of a parent object with a UUID primary key and a child object
|
| 53 |
+
with an AutoField primary key.
|
| 54 |
+
"""
|
| 55 |
+
FormSet = inlineformset_factory(
|
| 56 |
+
UUIDPKParent, AutoPKChildOfUUIDPKParent, fields="__all__"
|
| 57 |
+
)
|
| 58 |
+
formset = FormSet()
|
| 59 |
+
self.assertIsNone(formset.forms[0].fields["parent"].initial)
|
| 60 |
+
|
| 61 |
+
def test_inlineformset_factory_nulls_default_pks_auto_parent_uuid_child(self):
|
| 62 |
+
"""
|
| 63 |
+
#24958 - Variant of test_inlineformset_factory_nulls_default_pks for
|
| 64 |
+
the case of a parent object with an AutoField primary key and a child
|
| 65 |
+
object with a UUID primary key.
|
| 66 |
+
"""
|
| 67 |
+
FormSet = inlineformset_factory(
|
| 68 |
+
AutoPKParent, UUIDPKChildOfAutoPKParent, fields="__all__"
|
| 69 |
+
)
|
| 70 |
+
formset = FormSet()
|
| 71 |
+
self.assertIsNone(formset.forms[0].fields["parent"].initial)
|
| 72 |
+
|
| 73 |
+
def test_inlineformset_factory_nulls_default_pks_child_editable_pk(self):
|
| 74 |
+
"""
|
| 75 |
+
#24958 - Variant of test_inlineformset_factory_nulls_default_pks for
|
| 76 |
+
the case of a parent object with a UUID primary key and a child
|
| 77 |
+
object with an editable natural key for a primary key.
|
| 78 |
+
"""
|
| 79 |
+
FormSet = inlineformset_factory(
|
| 80 |
+
UUIDPKParent, ChildWithEditablePK, fields="__all__"
|
| 81 |
+
)
|
| 82 |
+
formset = FormSet()
|
| 83 |
+
self.assertIsNone(formset.forms[0].fields["parent"].initial)
|
| 84 |
+
|
| 85 |
+
def test_inlineformset_factory_nulls_default_pks_alternate_key_relation(self):
|
| 86 |
+
"""
|
| 87 |
+
#24958 - Variant of test_inlineformset_factory_nulls_default_pks for
|
| 88 |
+
the case of a parent object with a UUID alternate key and a child
|
| 89 |
+
object that relates to that alternate key.
|
| 90 |
+
"""
|
| 91 |
+
FormSet = inlineformset_factory(
|
| 92 |
+
ParentWithUUIDAlternateKey, ChildRelatedViaAK, fields="__all__"
|
| 93 |
+
)
|
| 94 |
+
formset = FormSet()
|
| 95 |
+
self.assertIsNone(formset.forms[0].fields["parent"].initial)
|
| 96 |
+
|
| 97 |
+
def test_inlineformset_factory_nulls_default_pks_alternate_key_relation_data(self):
|
| 98 |
+
"""
|
| 99 |
+
If form data is provided, a parent's auto-generated alternate key is
|
| 100 |
+
set.
|
| 101 |
+
"""
|
| 102 |
+
FormSet = inlineformset_factory(
|
| 103 |
+
ParentWithUUIDAlternateKey, ChildRelatedViaAK, fields="__all__"
|
| 104 |
+
)
|
| 105 |
+
formset = FormSet(
|
| 106 |
+
{
|
| 107 |
+
"childrelatedviaak_set-TOTAL_FORMS": 3,
|
| 108 |
+
"childrelatedviaak_set-INITIAL_FORMS": 0,
|
| 109 |
+
"childrelatedviaak_set-MAX_NUM_FORMS": "",
|
| 110 |
+
"childrelatedviaak_set-0-name": "Test",
|
| 111 |
+
"childrelatedviaak_set-1-name": "",
|
| 112 |
+
"childrelatedviaak_set-2-name": "",
|
| 113 |
+
}
|
| 114 |
+
)
|
| 115 |
+
self.assertIs(formset.is_valid(), True)
|
| 116 |
+
self.assertIsNotNone(formset.instance.uuid)
|
| 117 |
+
self.assertEqual(formset.forms[0].instance.parent_id, formset.instance.uuid)
|
testbed/django__django/tests/model_formsets/tests.py
ADDED
|
@@ -0,0 +1,2367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import re
|
| 3 |
+
from datetime import date
|
| 4 |
+
from decimal import Decimal
|
| 5 |
+
|
| 6 |
+
from django import forms
|
| 7 |
+
from django.core.exceptions import ImproperlyConfigured
|
| 8 |
+
from django.db import models
|
| 9 |
+
from django.forms.formsets import formset_factory
|
| 10 |
+
from django.forms.models import (
|
| 11 |
+
BaseModelFormSet,
|
| 12 |
+
_get_foreign_key,
|
| 13 |
+
inlineformset_factory,
|
| 14 |
+
modelformset_factory,
|
| 15 |
+
)
|
| 16 |
+
from django.http import QueryDict
|
| 17 |
+
from django.test import TestCase, skipUnlessDBFeature
|
| 18 |
+
|
| 19 |
+
from .models import (
|
| 20 |
+
AlternateBook,
|
| 21 |
+
Author,
|
| 22 |
+
AuthorMeeting,
|
| 23 |
+
BetterAuthor,
|
| 24 |
+
Book,
|
| 25 |
+
BookWithCustomPK,
|
| 26 |
+
BookWithOptionalAltEditor,
|
| 27 |
+
ClassyMexicanRestaurant,
|
| 28 |
+
CustomPrimaryKey,
|
| 29 |
+
Location,
|
| 30 |
+
Membership,
|
| 31 |
+
MexicanRestaurant,
|
| 32 |
+
Owner,
|
| 33 |
+
OwnerProfile,
|
| 34 |
+
Person,
|
| 35 |
+
Place,
|
| 36 |
+
Player,
|
| 37 |
+
Poem,
|
| 38 |
+
Poet,
|
| 39 |
+
Post,
|
| 40 |
+
Price,
|
| 41 |
+
Product,
|
| 42 |
+
Repository,
|
| 43 |
+
Restaurant,
|
| 44 |
+
Revision,
|
| 45 |
+
Team,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class DeletionTests(TestCase):
|
| 50 |
+
def test_deletion(self):
|
| 51 |
+
PoetFormSet = modelformset_factory(Poet, fields="__all__", can_delete=True)
|
| 52 |
+
poet = Poet.objects.create(name="test")
|
| 53 |
+
data = {
|
| 54 |
+
"form-TOTAL_FORMS": "1",
|
| 55 |
+
"form-INITIAL_FORMS": "1",
|
| 56 |
+
"form-MAX_NUM_FORMS": "0",
|
| 57 |
+
"form-0-id": str(poet.pk),
|
| 58 |
+
"form-0-name": "test",
|
| 59 |
+
"form-0-DELETE": "on",
|
| 60 |
+
}
|
| 61 |
+
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
| 62 |
+
formset.save(commit=False)
|
| 63 |
+
self.assertEqual(Poet.objects.count(), 1)
|
| 64 |
+
|
| 65 |
+
formset.save()
|
| 66 |
+
self.assertTrue(formset.is_valid())
|
| 67 |
+
self.assertEqual(Poet.objects.count(), 0)
|
| 68 |
+
|
| 69 |
+
def test_add_form_deletion_when_invalid(self):
|
| 70 |
+
"""
|
| 71 |
+
Make sure that an add form that is filled out, but marked for deletion
|
| 72 |
+
doesn't cause validation errors.
|
| 73 |
+
"""
|
| 74 |
+
PoetFormSet = modelformset_factory(Poet, fields="__all__", can_delete=True)
|
| 75 |
+
poet = Poet.objects.create(name="test")
|
| 76 |
+
# One existing untouched and two new unvalid forms
|
| 77 |
+
data = {
|
| 78 |
+
"form-TOTAL_FORMS": "3",
|
| 79 |
+
"form-INITIAL_FORMS": "1",
|
| 80 |
+
"form-MAX_NUM_FORMS": "0",
|
| 81 |
+
"form-0-id": str(poet.id),
|
| 82 |
+
"form-0-name": "test",
|
| 83 |
+
"form-1-id": "",
|
| 84 |
+
"form-1-name": "x" * 1000, # Too long
|
| 85 |
+
"form-2-id": str(poet.id), # Violate unique constraint
|
| 86 |
+
"form-2-name": "test2",
|
| 87 |
+
}
|
| 88 |
+
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
| 89 |
+
# Make sure this form doesn't pass validation.
|
| 90 |
+
self.assertIs(formset.is_valid(), False)
|
| 91 |
+
self.assertEqual(Poet.objects.count(), 1)
|
| 92 |
+
|
| 93 |
+
# Then make sure that it *does* pass validation and delete the object,
|
| 94 |
+
# even though the data in new forms aren't actually valid.
|
| 95 |
+
data["form-0-DELETE"] = "on"
|
| 96 |
+
data["form-1-DELETE"] = "on"
|
| 97 |
+
data["form-2-DELETE"] = "on"
|
| 98 |
+
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
| 99 |
+
self.assertIs(formset.is_valid(), True)
|
| 100 |
+
formset.save()
|
| 101 |
+
self.assertEqual(Poet.objects.count(), 0)
|
| 102 |
+
|
| 103 |
+
def test_change_form_deletion_when_invalid(self):
|
| 104 |
+
"""
|
| 105 |
+
Make sure that a change form that is filled out, but marked for deletion
|
| 106 |
+
doesn't cause validation errors.
|
| 107 |
+
"""
|
| 108 |
+
PoetFormSet = modelformset_factory(Poet, fields="__all__", can_delete=True)
|
| 109 |
+
poet = Poet.objects.create(name="test")
|
| 110 |
+
data = {
|
| 111 |
+
"form-TOTAL_FORMS": "1",
|
| 112 |
+
"form-INITIAL_FORMS": "1",
|
| 113 |
+
"form-MAX_NUM_FORMS": "0",
|
| 114 |
+
"form-0-id": str(poet.id),
|
| 115 |
+
"form-0-name": "x" * 1000,
|
| 116 |
+
}
|
| 117 |
+
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
| 118 |
+
# Make sure this form doesn't pass validation.
|
| 119 |
+
self.assertIs(formset.is_valid(), False)
|
| 120 |
+
self.assertEqual(Poet.objects.count(), 1)
|
| 121 |
+
|
| 122 |
+
# Then make sure that it *does* pass validation and delete the object,
|
| 123 |
+
# even though the data isn't actually valid.
|
| 124 |
+
data["form-0-DELETE"] = "on"
|
| 125 |
+
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
| 126 |
+
self.assertIs(formset.is_valid(), True)
|
| 127 |
+
formset.save()
|
| 128 |
+
self.assertEqual(Poet.objects.count(), 0)
|
| 129 |
+
|
| 130 |
+
def test_outdated_deletion(self):
|
| 131 |
+
poet = Poet.objects.create(name="test")
|
| 132 |
+
poem = Poem.objects.create(name="Brevity is the soul of wit", poet=poet)
|
| 133 |
+
|
| 134 |
+
PoemFormSet = inlineformset_factory(
|
| 135 |
+
Poet, Poem, fields="__all__", can_delete=True
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
# Simulate deletion of an object that doesn't exist in the database
|
| 139 |
+
data = {
|
| 140 |
+
"form-TOTAL_FORMS": "2",
|
| 141 |
+
"form-INITIAL_FORMS": "2",
|
| 142 |
+
"form-0-id": str(poem.pk),
|
| 143 |
+
"form-0-name": "foo",
|
| 144 |
+
"form-1-id": str(poem.pk + 1), # doesn't exist
|
| 145 |
+
"form-1-name": "bar",
|
| 146 |
+
"form-1-DELETE": "on",
|
| 147 |
+
}
|
| 148 |
+
formset = PoemFormSet(data, instance=poet, prefix="form")
|
| 149 |
+
|
| 150 |
+
# The formset is valid even though poem.pk + 1 doesn't exist,
|
| 151 |
+
# because it's marked for deletion anyway
|
| 152 |
+
self.assertTrue(formset.is_valid())
|
| 153 |
+
|
| 154 |
+
formset.save()
|
| 155 |
+
|
| 156 |
+
# Make sure the save went through correctly
|
| 157 |
+
self.assertEqual(Poem.objects.get(pk=poem.pk).name, "foo")
|
| 158 |
+
self.assertEqual(poet.poem_set.count(), 1)
|
| 159 |
+
self.assertFalse(Poem.objects.filter(pk=poem.pk + 1).exists())
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class ModelFormsetTest(TestCase):
|
| 163 |
+
def test_modelformset_factory_without_fields(self):
|
| 164 |
+
"""Regression for #19733"""
|
| 165 |
+
message = (
|
| 166 |
+
"Calling modelformset_factory without defining 'fields' or 'exclude' "
|
| 167 |
+
"explicitly is prohibited."
|
| 168 |
+
)
|
| 169 |
+
with self.assertRaisesMessage(ImproperlyConfigured, message):
|
| 170 |
+
modelformset_factory(Author)
|
| 171 |
+
|
| 172 |
+
def test_simple_save(self):
|
| 173 |
+
qs = Author.objects.all()
|
| 174 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", extra=3)
|
| 175 |
+
|
| 176 |
+
formset = AuthorFormSet(queryset=qs)
|
| 177 |
+
self.assertEqual(len(formset.forms), 3)
|
| 178 |
+
self.assertHTMLEqual(
|
| 179 |
+
formset.forms[0].as_p(),
|
| 180 |
+
'<p><label for="id_form-0-name">Name:</label>'
|
| 181 |
+
'<input id="id_form-0-name" type="text" name="form-0-name" maxlength="100">'
|
| 182 |
+
'<input type="hidden" name="form-0-id" id="id_form-0-id"></p>',
|
| 183 |
+
)
|
| 184 |
+
self.assertHTMLEqual(
|
| 185 |
+
formset.forms[1].as_p(),
|
| 186 |
+
'<p><label for="id_form-1-name">Name:</label>'
|
| 187 |
+
'<input id="id_form-1-name" type="text" name="form-1-name" maxlength="100">'
|
| 188 |
+
'<input type="hidden" name="form-1-id" id="id_form-1-id"></p>',
|
| 189 |
+
)
|
| 190 |
+
self.assertHTMLEqual(
|
| 191 |
+
formset.forms[2].as_p(),
|
| 192 |
+
'<p><label for="id_form-2-name">Name:</label>'
|
| 193 |
+
'<input id="id_form-2-name" type="text" name="form-2-name" maxlength="100">'
|
| 194 |
+
'<input type="hidden" name="form-2-id" id="id_form-2-id"></p>',
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
data = {
|
| 198 |
+
"form-TOTAL_FORMS": "3", # the number of forms rendered
|
| 199 |
+
"form-INITIAL_FORMS": "0", # the number of forms with initial data
|
| 200 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 201 |
+
"form-0-name": "Charles Baudelaire",
|
| 202 |
+
"form-1-name": "Arthur Rimbaud",
|
| 203 |
+
"form-2-name": "",
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
formset = AuthorFormSet(data=data, queryset=qs)
|
| 207 |
+
self.assertTrue(formset.is_valid())
|
| 208 |
+
|
| 209 |
+
saved = formset.save()
|
| 210 |
+
self.assertEqual(len(saved), 2)
|
| 211 |
+
author1, author2 = saved
|
| 212 |
+
self.assertEqual(author1, Author.objects.get(name="Charles Baudelaire"))
|
| 213 |
+
self.assertEqual(author2, Author.objects.get(name="Arthur Rimbaud"))
|
| 214 |
+
|
| 215 |
+
authors = list(Author.objects.order_by("name"))
|
| 216 |
+
self.assertEqual(authors, [author2, author1])
|
| 217 |
+
|
| 218 |
+
# Gah! We forgot Paul Verlaine. Let's create a formset to edit the
|
| 219 |
+
# existing authors with an extra form to add him. We *could* pass in a
|
| 220 |
+
# queryset to restrict the Author objects we edit, but in this case
|
| 221 |
+
# we'll use it to display them in alphabetical order by name.
|
| 222 |
+
|
| 223 |
+
qs = Author.objects.order_by("name")
|
| 224 |
+
AuthorFormSet = modelformset_factory(
|
| 225 |
+
Author, fields="__all__", extra=1, can_delete=False
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
formset = AuthorFormSet(queryset=qs)
|
| 229 |
+
self.assertEqual(len(formset.forms), 3)
|
| 230 |
+
self.assertHTMLEqual(
|
| 231 |
+
formset.forms[0].as_p(),
|
| 232 |
+
'<p><label for="id_form-0-name">Name:</label>'
|
| 233 |
+
'<input id="id_form-0-name" type="text" name="form-0-name" '
|
| 234 |
+
'value="Arthur Rimbaud" maxlength="100">'
|
| 235 |
+
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id"></p>'
|
| 236 |
+
% author2.id,
|
| 237 |
+
)
|
| 238 |
+
self.assertHTMLEqual(
|
| 239 |
+
formset.forms[1].as_p(),
|
| 240 |
+
'<p><label for="id_form-1-name">Name:</label>'
|
| 241 |
+
'<input id="id_form-1-name" type="text" name="form-1-name" '
|
| 242 |
+
'value="Charles Baudelaire" maxlength="100">'
|
| 243 |
+
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id"></p>'
|
| 244 |
+
% author1.id,
|
| 245 |
+
)
|
| 246 |
+
self.assertHTMLEqual(
|
| 247 |
+
formset.forms[2].as_p(),
|
| 248 |
+
'<p><label for="id_form-2-name">Name:</label>'
|
| 249 |
+
'<input id="id_form-2-name" type="text" name="form-2-name" maxlength="100">'
|
| 250 |
+
'<input type="hidden" name="form-2-id" id="id_form-2-id"></p>',
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
data = {
|
| 254 |
+
"form-TOTAL_FORMS": "3", # the number of forms rendered
|
| 255 |
+
"form-INITIAL_FORMS": "2", # the number of forms with initial data
|
| 256 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 257 |
+
"form-0-id": str(author2.id),
|
| 258 |
+
"form-0-name": "Arthur Rimbaud",
|
| 259 |
+
"form-1-id": str(author1.id),
|
| 260 |
+
"form-1-name": "Charles Baudelaire",
|
| 261 |
+
"form-2-name": "Paul Verlaine",
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
formset = AuthorFormSet(data=data, queryset=qs)
|
| 265 |
+
self.assertTrue(formset.is_valid())
|
| 266 |
+
|
| 267 |
+
# Only changed or new objects are returned from formset.save()
|
| 268 |
+
saved = formset.save()
|
| 269 |
+
self.assertEqual(len(saved), 1)
|
| 270 |
+
author3 = saved[0]
|
| 271 |
+
self.assertEqual(author3, Author.objects.get(name="Paul Verlaine"))
|
| 272 |
+
|
| 273 |
+
authors = list(Author.objects.order_by("name"))
|
| 274 |
+
self.assertEqual(authors, [author2, author1, author3])
|
| 275 |
+
|
| 276 |
+
# This probably shouldn't happen, but it will. If an add form was
|
| 277 |
+
# marked for deletion, make sure we don't save that form.
|
| 278 |
+
|
| 279 |
+
qs = Author.objects.order_by("name")
|
| 280 |
+
AuthorFormSet = modelformset_factory(
|
| 281 |
+
Author, fields="__all__", extra=1, can_delete=True
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
formset = AuthorFormSet(queryset=qs)
|
| 285 |
+
self.assertEqual(len(formset.forms), 4)
|
| 286 |
+
self.assertHTMLEqual(
|
| 287 |
+
formset.forms[0].as_p(),
|
| 288 |
+
'<p><label for="id_form-0-name">Name:</label>'
|
| 289 |
+
'<input id="id_form-0-name" type="text" name="form-0-name" '
|
| 290 |
+
'value="Arthur Rimbaud" maxlength="100"></p>'
|
| 291 |
+
'<p><label for="id_form-0-DELETE">Delete:</label>'
|
| 292 |
+
'<input type="checkbox" name="form-0-DELETE" id="id_form-0-DELETE">'
|
| 293 |
+
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id"></p>'
|
| 294 |
+
% author2.id,
|
| 295 |
+
)
|
| 296 |
+
self.assertHTMLEqual(
|
| 297 |
+
formset.forms[1].as_p(),
|
| 298 |
+
'<p><label for="id_form-1-name">Name:</label>'
|
| 299 |
+
'<input id="id_form-1-name" type="text" name="form-1-name" '
|
| 300 |
+
'value="Charles Baudelaire" maxlength="100"></p>'
|
| 301 |
+
'<p><label for="id_form-1-DELETE">Delete:</label>'
|
| 302 |
+
'<input type="checkbox" name="form-1-DELETE" id="id_form-1-DELETE">'
|
| 303 |
+
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id"></p>'
|
| 304 |
+
% author1.id,
|
| 305 |
+
)
|
| 306 |
+
self.assertHTMLEqual(
|
| 307 |
+
formset.forms[2].as_p(),
|
| 308 |
+
'<p><label for="id_form-2-name">Name:</label>'
|
| 309 |
+
'<input id="id_form-2-name" type="text" name="form-2-name" '
|
| 310 |
+
'value="Paul Verlaine" maxlength="100"></p>'
|
| 311 |
+
'<p><label for="id_form-2-DELETE">Delete:</label>'
|
| 312 |
+
'<input type="checkbox" name="form-2-DELETE" id="id_form-2-DELETE">'
|
| 313 |
+
'<input type="hidden" name="form-2-id" value="%d" id="id_form-2-id"></p>'
|
| 314 |
+
% author3.id,
|
| 315 |
+
)
|
| 316 |
+
self.assertHTMLEqual(
|
| 317 |
+
formset.forms[3].as_p(),
|
| 318 |
+
'<p><label for="id_form-3-name">Name:</label>'
|
| 319 |
+
'<input id="id_form-3-name" type="text" name="form-3-name" maxlength="100">'
|
| 320 |
+
'</p><p><label for="id_form-3-DELETE">Delete:</label>'
|
| 321 |
+
'<input type="checkbox" name="form-3-DELETE" id="id_form-3-DELETE">'
|
| 322 |
+
'<input type="hidden" name="form-3-id" id="id_form-3-id"></p>',
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
data = {
|
| 326 |
+
"form-TOTAL_FORMS": "4", # the number of forms rendered
|
| 327 |
+
"form-INITIAL_FORMS": "3", # the number of forms with initial data
|
| 328 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 329 |
+
"form-0-id": str(author2.id),
|
| 330 |
+
"form-0-name": "Arthur Rimbaud",
|
| 331 |
+
"form-1-id": str(author1.id),
|
| 332 |
+
"form-1-name": "Charles Baudelaire",
|
| 333 |
+
"form-2-id": str(author3.id),
|
| 334 |
+
"form-2-name": "Paul Verlaine",
|
| 335 |
+
"form-3-name": "Walt Whitman",
|
| 336 |
+
"form-3-DELETE": "on",
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
formset = AuthorFormSet(data=data, queryset=qs)
|
| 340 |
+
self.assertTrue(formset.is_valid())
|
| 341 |
+
|
| 342 |
+
# No objects were changed or saved so nothing will come back.
|
| 343 |
+
|
| 344 |
+
self.assertEqual(formset.save(), [])
|
| 345 |
+
|
| 346 |
+
authors = list(Author.objects.order_by("name"))
|
| 347 |
+
self.assertEqual(authors, [author2, author1, author3])
|
| 348 |
+
|
| 349 |
+
# Let's edit a record to ensure save only returns that one record.
|
| 350 |
+
|
| 351 |
+
data = {
|
| 352 |
+
"form-TOTAL_FORMS": "4", # the number of forms rendered
|
| 353 |
+
"form-INITIAL_FORMS": "3", # the number of forms with initial data
|
| 354 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 355 |
+
"form-0-id": str(author2.id),
|
| 356 |
+
"form-0-name": "Walt Whitman",
|
| 357 |
+
"form-1-id": str(author1.id),
|
| 358 |
+
"form-1-name": "Charles Baudelaire",
|
| 359 |
+
"form-2-id": str(author3.id),
|
| 360 |
+
"form-2-name": "Paul Verlaine",
|
| 361 |
+
"form-3-name": "",
|
| 362 |
+
"form-3-DELETE": "",
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
formset = AuthorFormSet(data=data, queryset=qs)
|
| 366 |
+
self.assertTrue(formset.is_valid())
|
| 367 |
+
|
| 368 |
+
# One record has changed.
|
| 369 |
+
|
| 370 |
+
saved = formset.save()
|
| 371 |
+
self.assertEqual(len(saved), 1)
|
| 372 |
+
self.assertEqual(saved[0], Author.objects.get(name="Walt Whitman"))
|
| 373 |
+
|
| 374 |
+
def test_commit_false(self):
|
| 375 |
+
# Test the behavior of commit=False and save_m2m
|
| 376 |
+
|
| 377 |
+
author1 = Author.objects.create(name="Charles Baudelaire")
|
| 378 |
+
author2 = Author.objects.create(name="Paul Verlaine")
|
| 379 |
+
author3 = Author.objects.create(name="Walt Whitman")
|
| 380 |
+
|
| 381 |
+
meeting = AuthorMeeting.objects.create(created=date.today())
|
| 382 |
+
meeting.authors.set(Author.objects.all())
|
| 383 |
+
|
| 384 |
+
# create an Author instance to add to the meeting.
|
| 385 |
+
|
| 386 |
+
author4 = Author.objects.create(name="John Steinbeck")
|
| 387 |
+
|
| 388 |
+
AuthorMeetingFormSet = modelformset_factory(
|
| 389 |
+
AuthorMeeting, fields="__all__", extra=1, can_delete=True
|
| 390 |
+
)
|
| 391 |
+
data = {
|
| 392 |
+
"form-TOTAL_FORMS": "2", # the number of forms rendered
|
| 393 |
+
"form-INITIAL_FORMS": "1", # the number of forms with initial data
|
| 394 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 395 |
+
"form-0-id": str(meeting.id),
|
| 396 |
+
"form-0-name": "2nd Tuesday of the Week Meeting",
|
| 397 |
+
"form-0-authors": [author2.id, author1.id, author3.id, author4.id],
|
| 398 |
+
"form-1-name": "",
|
| 399 |
+
"form-1-authors": "",
|
| 400 |
+
"form-1-DELETE": "",
|
| 401 |
+
}
|
| 402 |
+
formset = AuthorMeetingFormSet(data=data, queryset=AuthorMeeting.objects.all())
|
| 403 |
+
self.assertTrue(formset.is_valid())
|
| 404 |
+
|
| 405 |
+
instances = formset.save(commit=False)
|
| 406 |
+
for instance in instances:
|
| 407 |
+
instance.created = date.today()
|
| 408 |
+
instance.save()
|
| 409 |
+
formset.save_m2m()
|
| 410 |
+
self.assertSequenceEqual(
|
| 411 |
+
instances[0].authors.all(),
|
| 412 |
+
[author1, author4, author2, author3],
|
| 413 |
+
)
|
| 414 |
+
|
| 415 |
+
def test_max_num(self):
|
| 416 |
+
# Test the behavior of max_num with model formsets. It should allow
|
| 417 |
+
# all existing related objects/inlines for a given object to be
|
| 418 |
+
# displayed, but not allow the creation of new inlines beyond max_num.
|
| 419 |
+
|
| 420 |
+
a1 = Author.objects.create(name="Charles Baudelaire")
|
| 421 |
+
a2 = Author.objects.create(name="Paul Verlaine")
|
| 422 |
+
a3 = Author.objects.create(name="Walt Whitman")
|
| 423 |
+
|
| 424 |
+
qs = Author.objects.order_by("name")
|
| 425 |
+
|
| 426 |
+
AuthorFormSet = modelformset_factory(
|
| 427 |
+
Author, fields="__all__", max_num=None, extra=3
|
| 428 |
+
)
|
| 429 |
+
formset = AuthorFormSet(queryset=qs)
|
| 430 |
+
self.assertEqual(len(formset.forms), 6)
|
| 431 |
+
self.assertEqual(len(formset.extra_forms), 3)
|
| 432 |
+
|
| 433 |
+
AuthorFormSet = modelformset_factory(
|
| 434 |
+
Author, fields="__all__", max_num=4, extra=3
|
| 435 |
+
)
|
| 436 |
+
formset = AuthorFormSet(queryset=qs)
|
| 437 |
+
self.assertEqual(len(formset.forms), 4)
|
| 438 |
+
self.assertEqual(len(formset.extra_forms), 1)
|
| 439 |
+
|
| 440 |
+
AuthorFormSet = modelformset_factory(
|
| 441 |
+
Author, fields="__all__", max_num=0, extra=3
|
| 442 |
+
)
|
| 443 |
+
formset = AuthorFormSet(queryset=qs)
|
| 444 |
+
self.assertEqual(len(formset.forms), 3)
|
| 445 |
+
self.assertEqual(len(formset.extra_forms), 0)
|
| 446 |
+
|
| 447 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", max_num=None)
|
| 448 |
+
formset = AuthorFormSet(queryset=qs)
|
| 449 |
+
self.assertSequenceEqual(formset.get_queryset(), [a1, a2, a3])
|
| 450 |
+
|
| 451 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", max_num=0)
|
| 452 |
+
formset = AuthorFormSet(queryset=qs)
|
| 453 |
+
self.assertSequenceEqual(formset.get_queryset(), [a1, a2, a3])
|
| 454 |
+
|
| 455 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", max_num=4)
|
| 456 |
+
formset = AuthorFormSet(queryset=qs)
|
| 457 |
+
self.assertSequenceEqual(formset.get_queryset(), [a1, a2, a3])
|
| 458 |
+
|
| 459 |
+
def test_min_num(self):
|
| 460 |
+
# Test the behavior of min_num with model formsets. It should be
|
| 461 |
+
# added to extra.
|
| 462 |
+
qs = Author.objects.none()
|
| 463 |
+
|
| 464 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", extra=0)
|
| 465 |
+
formset = AuthorFormSet(queryset=qs)
|
| 466 |
+
self.assertEqual(len(formset.forms), 0)
|
| 467 |
+
|
| 468 |
+
AuthorFormSet = modelformset_factory(
|
| 469 |
+
Author, fields="__all__", min_num=1, extra=0
|
| 470 |
+
)
|
| 471 |
+
formset = AuthorFormSet(queryset=qs)
|
| 472 |
+
self.assertEqual(len(formset.forms), 1)
|
| 473 |
+
|
| 474 |
+
AuthorFormSet = modelformset_factory(
|
| 475 |
+
Author, fields="__all__", min_num=1, extra=1
|
| 476 |
+
)
|
| 477 |
+
formset = AuthorFormSet(queryset=qs)
|
| 478 |
+
self.assertEqual(len(formset.forms), 2)
|
| 479 |
+
|
| 480 |
+
def test_min_num_with_existing(self):
|
| 481 |
+
# Test the behavior of min_num with existing objects.
|
| 482 |
+
Author.objects.create(name="Charles Baudelaire")
|
| 483 |
+
qs = Author.objects.all()
|
| 484 |
+
|
| 485 |
+
AuthorFormSet = modelformset_factory(
|
| 486 |
+
Author, fields="__all__", extra=0, min_num=1
|
| 487 |
+
)
|
| 488 |
+
formset = AuthorFormSet(queryset=qs)
|
| 489 |
+
self.assertEqual(len(formset.forms), 1)
|
| 490 |
+
|
| 491 |
+
def test_custom_save_method(self):
|
| 492 |
+
class PoetForm(forms.ModelForm):
|
| 493 |
+
def save(self, commit=True):
|
| 494 |
+
# change the name to "Vladimir Mayakovsky" just to be a jerk.
|
| 495 |
+
author = super().save(commit=False)
|
| 496 |
+
author.name = "Vladimir Mayakovsky"
|
| 497 |
+
if commit:
|
| 498 |
+
author.save()
|
| 499 |
+
return author
|
| 500 |
+
|
| 501 |
+
PoetFormSet = modelformset_factory(Poet, fields="__all__", form=PoetForm)
|
| 502 |
+
|
| 503 |
+
data = {
|
| 504 |
+
"form-TOTAL_FORMS": "3", # the number of forms rendered
|
| 505 |
+
"form-INITIAL_FORMS": "0", # the number of forms with initial data
|
| 506 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 507 |
+
"form-0-name": "Walt Whitman",
|
| 508 |
+
"form-1-name": "Charles Baudelaire",
|
| 509 |
+
"form-2-name": "",
|
| 510 |
+
}
|
| 511 |
+
|
| 512 |
+
qs = Poet.objects.all()
|
| 513 |
+
formset = PoetFormSet(data=data, queryset=qs)
|
| 514 |
+
self.assertTrue(formset.is_valid())
|
| 515 |
+
|
| 516 |
+
poets = formset.save()
|
| 517 |
+
self.assertEqual(len(poets), 2)
|
| 518 |
+
poet1, poet2 = poets
|
| 519 |
+
self.assertEqual(poet1.name, "Vladimir Mayakovsky")
|
| 520 |
+
self.assertEqual(poet2.name, "Vladimir Mayakovsky")
|
| 521 |
+
|
| 522 |
+
def test_custom_form(self):
|
| 523 |
+
"""
|
| 524 |
+
model_formset_factory() respects fields and exclude parameters of a
|
| 525 |
+
custom form.
|
| 526 |
+
"""
|
| 527 |
+
|
| 528 |
+
class PostForm1(forms.ModelForm):
|
| 529 |
+
class Meta:
|
| 530 |
+
model = Post
|
| 531 |
+
fields = ("title", "posted")
|
| 532 |
+
|
| 533 |
+
class PostForm2(forms.ModelForm):
|
| 534 |
+
class Meta:
|
| 535 |
+
model = Post
|
| 536 |
+
exclude = ("subtitle",)
|
| 537 |
+
|
| 538 |
+
PostFormSet = modelformset_factory(Post, form=PostForm1)
|
| 539 |
+
formset = PostFormSet()
|
| 540 |
+
self.assertNotIn("subtitle", formset.forms[0].fields)
|
| 541 |
+
|
| 542 |
+
PostFormSet = modelformset_factory(Post, form=PostForm2)
|
| 543 |
+
formset = PostFormSet()
|
| 544 |
+
self.assertNotIn("subtitle", formset.forms[0].fields)
|
| 545 |
+
|
| 546 |
+
def test_custom_queryset_init(self):
|
| 547 |
+
"""
|
| 548 |
+
A queryset can be overridden in the formset's __init__() method.
|
| 549 |
+
"""
|
| 550 |
+
Author.objects.create(name="Charles Baudelaire")
|
| 551 |
+
Author.objects.create(name="Paul Verlaine")
|
| 552 |
+
|
| 553 |
+
class BaseAuthorFormSet(BaseModelFormSet):
|
| 554 |
+
def __init__(self, *args, **kwargs):
|
| 555 |
+
super().__init__(*args, **kwargs)
|
| 556 |
+
self.queryset = Author.objects.filter(name__startswith="Charles")
|
| 557 |
+
|
| 558 |
+
AuthorFormSet = modelformset_factory(
|
| 559 |
+
Author, fields="__all__", formset=BaseAuthorFormSet
|
| 560 |
+
)
|
| 561 |
+
formset = AuthorFormSet()
|
| 562 |
+
self.assertEqual(len(formset.get_queryset()), 1)
|
| 563 |
+
|
| 564 |
+
def test_model_inheritance(self):
|
| 565 |
+
BetterAuthorFormSet = modelformset_factory(BetterAuthor, fields="__all__")
|
| 566 |
+
formset = BetterAuthorFormSet()
|
| 567 |
+
self.assertEqual(len(formset.forms), 1)
|
| 568 |
+
self.assertHTMLEqual(
|
| 569 |
+
formset.forms[0].as_p(),
|
| 570 |
+
'<p><label for="id_form-0-name">Name:</label>'
|
| 571 |
+
'<input id="id_form-0-name" type="text" name="form-0-name" maxlength="100">'
|
| 572 |
+
'</p><p><label for="id_form-0-write_speed">Write speed:</label>'
|
| 573 |
+
'<input type="number" name="form-0-write_speed" id="id_form-0-write_speed">'
|
| 574 |
+
'<input type="hidden" name="form-0-author_ptr" id="id_form-0-author_ptr">'
|
| 575 |
+
"</p>",
|
| 576 |
+
)
|
| 577 |
+
|
| 578 |
+
data = {
|
| 579 |
+
"form-TOTAL_FORMS": "1", # the number of forms rendered
|
| 580 |
+
"form-INITIAL_FORMS": "0", # the number of forms with initial data
|
| 581 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 582 |
+
"form-0-author_ptr": "",
|
| 583 |
+
"form-0-name": "Ernest Hemingway",
|
| 584 |
+
"form-0-write_speed": "10",
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
formset = BetterAuthorFormSet(data)
|
| 588 |
+
self.assertTrue(formset.is_valid())
|
| 589 |
+
saved = formset.save()
|
| 590 |
+
self.assertEqual(len(saved), 1)
|
| 591 |
+
(author1,) = saved
|
| 592 |
+
self.assertEqual(author1, BetterAuthor.objects.get(name="Ernest Hemingway"))
|
| 593 |
+
hemingway_id = BetterAuthor.objects.get(name="Ernest Hemingway").pk
|
| 594 |
+
|
| 595 |
+
formset = BetterAuthorFormSet()
|
| 596 |
+
self.assertEqual(len(formset.forms), 2)
|
| 597 |
+
self.assertHTMLEqual(
|
| 598 |
+
formset.forms[0].as_p(),
|
| 599 |
+
'<p><label for="id_form-0-name">Name:</label>'
|
| 600 |
+
'<input id="id_form-0-name" type="text" name="form-0-name" '
|
| 601 |
+
'value="Ernest Hemingway" maxlength="100"></p>'
|
| 602 |
+
'<p><label for="id_form-0-write_speed">Write speed:</label>'
|
| 603 |
+
'<input type="number" name="form-0-write_speed" value="10" '
|
| 604 |
+
'id="id_form-0-write_speed">'
|
| 605 |
+
'<input type="hidden" name="form-0-author_ptr" value="%d" '
|
| 606 |
+
'id="id_form-0-author_ptr"></p>' % hemingway_id,
|
| 607 |
+
)
|
| 608 |
+
self.assertHTMLEqual(
|
| 609 |
+
formset.forms[1].as_p(),
|
| 610 |
+
'<p><label for="id_form-1-name">Name:</label>'
|
| 611 |
+
'<input id="id_form-1-name" type="text" name="form-1-name" maxlength="100">'
|
| 612 |
+
'</p><p><label for="id_form-1-write_speed">Write speed:</label>'
|
| 613 |
+
'<input type="number" name="form-1-write_speed" id="id_form-1-write_speed">'
|
| 614 |
+
'<input type="hidden" name="form-1-author_ptr" id="id_form-1-author_ptr">'
|
| 615 |
+
"</p>",
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
+
data = {
|
| 619 |
+
"form-TOTAL_FORMS": "2", # the number of forms rendered
|
| 620 |
+
"form-INITIAL_FORMS": "1", # the number of forms with initial data
|
| 621 |
+
"form-MAX_NUM_FORMS": "", # the max number of forms
|
| 622 |
+
"form-0-author_ptr": hemingway_id,
|
| 623 |
+
"form-0-name": "Ernest Hemingway",
|
| 624 |
+
"form-0-write_speed": "10",
|
| 625 |
+
"form-1-author_ptr": "",
|
| 626 |
+
"form-1-name": "",
|
| 627 |
+
"form-1-write_speed": "",
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
formset = BetterAuthorFormSet(data)
|
| 631 |
+
self.assertTrue(formset.is_valid())
|
| 632 |
+
self.assertEqual(formset.save(), [])
|
| 633 |
+
|
| 634 |
+
def test_inline_formsets(self):
|
| 635 |
+
# We can also create a formset that is tied to a parent model. This is
|
| 636 |
+
# how the admin system's edit inline functionality works.
|
| 637 |
+
|
| 638 |
+
AuthorBooksFormSet = inlineformset_factory(
|
| 639 |
+
Author, Book, can_delete=False, extra=3, fields="__all__"
|
| 640 |
+
)
|
| 641 |
+
author = Author.objects.create(name="Charles Baudelaire")
|
| 642 |
+
|
| 643 |
+
formset = AuthorBooksFormSet(instance=author)
|
| 644 |
+
self.assertEqual(len(formset.forms), 3)
|
| 645 |
+
self.assertHTMLEqual(
|
| 646 |
+
formset.forms[0].as_p(),
|
| 647 |
+
'<p><label for="id_book_set-0-title">Title:</label>'
|
| 648 |
+
'<input id="id_book_set-0-title" type="text" name="book_set-0-title" '
|
| 649 |
+
'maxlength="100">'
|
| 650 |
+
'<input type="hidden" name="book_set-0-author" value="%d" '
|
| 651 |
+
'id="id_book_set-0-author">'
|
| 652 |
+
'<input type="hidden" name="book_set-0-id" id="id_book_set-0-id">'
|
| 653 |
+
"</p>" % author.id,
|
| 654 |
+
)
|
| 655 |
+
self.assertHTMLEqual(
|
| 656 |
+
formset.forms[1].as_p(),
|
| 657 |
+
'<p><label for="id_book_set-1-title">Title:</label>'
|
| 658 |
+
'<input id="id_book_set-1-title" type="text" name="book_set-1-title" '
|
| 659 |
+
'maxlength="100">'
|
| 660 |
+
'<input type="hidden" name="book_set-1-author" value="%d" '
|
| 661 |
+
'id="id_book_set-1-author">'
|
| 662 |
+
'<input type="hidden" name="book_set-1-id" id="id_book_set-1-id"></p>'
|
| 663 |
+
% author.id,
|
| 664 |
+
)
|
| 665 |
+
self.assertHTMLEqual(
|
| 666 |
+
formset.forms[2].as_p(),
|
| 667 |
+
'<p><label for="id_book_set-2-title">Title:</label>'
|
| 668 |
+
'<input id="id_book_set-2-title" type="text" name="book_set-2-title" '
|
| 669 |
+
'maxlength="100">'
|
| 670 |
+
'<input type="hidden" name="book_set-2-author" value="%d" '
|
| 671 |
+
'id="id_book_set-2-author">'
|
| 672 |
+
'<input type="hidden" name="book_set-2-id" id="id_book_set-2-id"></p>'
|
| 673 |
+
% author.id,
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
data = {
|
| 677 |
+
"book_set-TOTAL_FORMS": "3", # the number of forms rendered
|
| 678 |
+
"book_set-INITIAL_FORMS": "0", # the number of forms with initial data
|
| 679 |
+
"book_set-MAX_NUM_FORMS": "", # the max number of forms
|
| 680 |
+
"book_set-0-title": "Les Fleurs du Mal",
|
| 681 |
+
"book_set-1-title": "",
|
| 682 |
+
"book_set-2-title": "",
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
formset = AuthorBooksFormSet(data, instance=author)
|
| 686 |
+
self.assertTrue(formset.is_valid())
|
| 687 |
+
|
| 688 |
+
saved = formset.save()
|
| 689 |
+
self.assertEqual(len(saved), 1)
|
| 690 |
+
(book1,) = saved
|
| 691 |
+
self.assertEqual(book1, Book.objects.get(title="Les Fleurs du Mal"))
|
| 692 |
+
self.assertSequenceEqual(author.book_set.all(), [book1])
|
| 693 |
+
|
| 694 |
+
# Now that we've added a book to Charles Baudelaire, let's try adding
|
| 695 |
+
# another one. This time though, an edit form will be available for
|
| 696 |
+
# every existing book.
|
| 697 |
+
|
| 698 |
+
AuthorBooksFormSet = inlineformset_factory(
|
| 699 |
+
Author, Book, can_delete=False, extra=2, fields="__all__"
|
| 700 |
+
)
|
| 701 |
+
author = Author.objects.get(name="Charles Baudelaire")
|
| 702 |
+
|
| 703 |
+
formset = AuthorBooksFormSet(instance=author)
|
| 704 |
+
self.assertEqual(len(formset.forms), 3)
|
| 705 |
+
self.assertHTMLEqual(
|
| 706 |
+
formset.forms[0].as_p(),
|
| 707 |
+
'<p><label for="id_book_set-0-title">Title:</label>'
|
| 708 |
+
'<input id="id_book_set-0-title" type="text" name="book_set-0-title" '
|
| 709 |
+
'value="Les Fleurs du Mal" maxlength="100">'
|
| 710 |
+
'<input type="hidden" name="book_set-0-author" value="%d" '
|
| 711 |
+
'id="id_book_set-0-author">'
|
| 712 |
+
'<input type="hidden" name="book_set-0-id" value="%d" '
|
| 713 |
+
'id="id_book_set-0-id"></p>'
|
| 714 |
+
% (
|
| 715 |
+
author.id,
|
| 716 |
+
book1.id,
|
| 717 |
+
),
|
| 718 |
+
)
|
| 719 |
+
self.assertHTMLEqual(
|
| 720 |
+
formset.forms[1].as_p(),
|
| 721 |
+
'<p><label for="id_book_set-1-title">Title:</label>'
|
| 722 |
+
'<input id="id_book_set-1-title" type="text" name="book_set-1-title" '
|
| 723 |
+
'maxlength="100">'
|
| 724 |
+
'<input type="hidden" name="book_set-1-author" value="%d" '
|
| 725 |
+
'id="id_book_set-1-author">'
|
| 726 |
+
'<input type="hidden" name="book_set-1-id" id="id_book_set-1-id"></p>'
|
| 727 |
+
% author.id,
|
| 728 |
+
)
|
| 729 |
+
self.assertHTMLEqual(
|
| 730 |
+
formset.forms[2].as_p(),
|
| 731 |
+
'<p><label for="id_book_set-2-title">Title:</label>'
|
| 732 |
+
'<input id="id_book_set-2-title" type="text" name="book_set-2-title" '
|
| 733 |
+
'maxlength="100">'
|
| 734 |
+
'<input type="hidden" name="book_set-2-author" value="%d" '
|
| 735 |
+
'id="id_book_set-2-author">'
|
| 736 |
+
'<input type="hidden" name="book_set-2-id" id="id_book_set-2-id"></p>'
|
| 737 |
+
% author.id,
|
| 738 |
+
)
|
| 739 |
+
|
| 740 |
+
data = {
|
| 741 |
+
"book_set-TOTAL_FORMS": "3", # the number of forms rendered
|
| 742 |
+
"book_set-INITIAL_FORMS": "1", # the number of forms with initial data
|
| 743 |
+
"book_set-MAX_NUM_FORMS": "", # the max number of forms
|
| 744 |
+
"book_set-0-id": str(book1.id),
|
| 745 |
+
"book_set-0-title": "Les Fleurs du Mal",
|
| 746 |
+
"book_set-1-title": "Les Paradis Artificiels",
|
| 747 |
+
"book_set-2-title": "",
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
formset = AuthorBooksFormSet(data, instance=author)
|
| 751 |
+
self.assertTrue(formset.is_valid())
|
| 752 |
+
|
| 753 |
+
saved = formset.save()
|
| 754 |
+
self.assertEqual(len(saved), 1)
|
| 755 |
+
(book2,) = saved
|
| 756 |
+
self.assertEqual(book2, Book.objects.get(title="Les Paradis Artificiels"))
|
| 757 |
+
|
| 758 |
+
# As you can see, 'Les Paradis Artificiels' is now a book belonging to
|
| 759 |
+
# Charles Baudelaire.
|
| 760 |
+
self.assertSequenceEqual(author.book_set.order_by("title"), [book1, book2])
|
| 761 |
+
|
| 762 |
+
def test_inline_formsets_save_as_new(self):
|
| 763 |
+
# The save_as_new parameter lets you re-associate the data to a new
|
| 764 |
+
# instance. This is used in the admin for save_as functionality.
|
| 765 |
+
AuthorBooksFormSet = inlineformset_factory(
|
| 766 |
+
Author, Book, can_delete=False, extra=2, fields="__all__"
|
| 767 |
+
)
|
| 768 |
+
Author.objects.create(name="Charles Baudelaire")
|
| 769 |
+
|
| 770 |
+
# An immutable QueryDict simulates request.POST.
|
| 771 |
+
data = QueryDict(mutable=True)
|
| 772 |
+
data.update(
|
| 773 |
+
{
|
| 774 |
+
"book_set-TOTAL_FORMS": "3", # the number of forms rendered
|
| 775 |
+
"book_set-INITIAL_FORMS": "2", # the number of forms with initial data
|
| 776 |
+
"book_set-MAX_NUM_FORMS": "", # the max number of forms
|
| 777 |
+
"book_set-0-id": "1",
|
| 778 |
+
"book_set-0-title": "Les Fleurs du Mal",
|
| 779 |
+
"book_set-1-id": "2",
|
| 780 |
+
"book_set-1-title": "Les Paradis Artificiels",
|
| 781 |
+
"book_set-2-title": "",
|
| 782 |
+
}
|
| 783 |
+
)
|
| 784 |
+
data._mutable = False
|
| 785 |
+
|
| 786 |
+
formset = AuthorBooksFormSet(data, instance=Author(), save_as_new=True)
|
| 787 |
+
self.assertTrue(formset.is_valid())
|
| 788 |
+
self.assertIs(data._mutable, False)
|
| 789 |
+
|
| 790 |
+
new_author = Author.objects.create(name="Charles Baudelaire")
|
| 791 |
+
formset = AuthorBooksFormSet(data, instance=new_author, save_as_new=True)
|
| 792 |
+
saved = formset.save()
|
| 793 |
+
self.assertEqual(len(saved), 2)
|
| 794 |
+
book1, book2 = saved
|
| 795 |
+
self.assertEqual(book1.title, "Les Fleurs du Mal")
|
| 796 |
+
self.assertEqual(book2.title, "Les Paradis Artificiels")
|
| 797 |
+
|
| 798 |
+
# Test using a custom prefix on an inline formset.
|
| 799 |
+
|
| 800 |
+
formset = AuthorBooksFormSet(prefix="test")
|
| 801 |
+
self.assertEqual(len(formset.forms), 2)
|
| 802 |
+
self.assertHTMLEqual(
|
| 803 |
+
formset.forms[0].as_p(),
|
| 804 |
+
'<p><label for="id_test-0-title">Title:</label>'
|
| 805 |
+
'<input id="id_test-0-title" type="text" name="test-0-title" '
|
| 806 |
+
'maxlength="100">'
|
| 807 |
+
'<input type="hidden" name="test-0-author" id="id_test-0-author">'
|
| 808 |
+
'<input type="hidden" name="test-0-id" id="id_test-0-id"></p>',
|
| 809 |
+
)
|
| 810 |
+
|
| 811 |
+
self.assertHTMLEqual(
|
| 812 |
+
formset.forms[1].as_p(),
|
| 813 |
+
'<p><label for="id_test-1-title">Title:</label>'
|
| 814 |
+
'<input id="id_test-1-title" type="text" name="test-1-title" '
|
| 815 |
+
'maxlength="100">'
|
| 816 |
+
'<input type="hidden" name="test-1-author" id="id_test-1-author">'
|
| 817 |
+
'<input type="hidden" name="test-1-id" id="id_test-1-id"></p>',
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
def test_inline_formsets_with_custom_pk(self):
|
| 821 |
+
# Test inline formsets where the inline-edited object has a custom
|
| 822 |
+
# primary key that is not the fk to the parent object.
|
| 823 |
+
self.maxDiff = 1024
|
| 824 |
+
|
| 825 |
+
AuthorBooksFormSet2 = inlineformset_factory(
|
| 826 |
+
Author, BookWithCustomPK, can_delete=False, extra=1, fields="__all__"
|
| 827 |
+
)
|
| 828 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 829 |
+
|
| 830 |
+
formset = AuthorBooksFormSet2(instance=author)
|
| 831 |
+
self.assertEqual(len(formset.forms), 1)
|
| 832 |
+
self.assertHTMLEqual(
|
| 833 |
+
formset.forms[0].as_p(),
|
| 834 |
+
'<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label>'
|
| 835 |
+
'<input id="id_bookwithcustompk_set-0-my_pk" type="number" '
|
| 836 |
+
'name="bookwithcustompk_set-0-my_pk" step="1"></p>'
|
| 837 |
+
'<p><label for="id_bookwithcustompk_set-0-title">Title:</label>'
|
| 838 |
+
'<input id="id_bookwithcustompk_set-0-title" type="text" '
|
| 839 |
+
'name="bookwithcustompk_set-0-title" maxlength="100">'
|
| 840 |
+
'<input type="hidden" name="bookwithcustompk_set-0-author" '
|
| 841 |
+
'value="1" id="id_bookwithcustompk_set-0-author"></p>',
|
| 842 |
+
)
|
| 843 |
+
|
| 844 |
+
data = {
|
| 845 |
+
# The number of forms rendered.
|
| 846 |
+
"bookwithcustompk_set-TOTAL_FORMS": "1",
|
| 847 |
+
# The number of forms with initial data.
|
| 848 |
+
"bookwithcustompk_set-INITIAL_FORMS": "0",
|
| 849 |
+
# The max number of forms.
|
| 850 |
+
"bookwithcustompk_set-MAX_NUM_FORMS": "",
|
| 851 |
+
"bookwithcustompk_set-0-my_pk": "77777",
|
| 852 |
+
"bookwithcustompk_set-0-title": "Les Fleurs du Mal",
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
formset = AuthorBooksFormSet2(data, instance=author)
|
| 856 |
+
self.assertTrue(formset.is_valid())
|
| 857 |
+
|
| 858 |
+
saved = formset.save()
|
| 859 |
+
self.assertEqual(len(saved), 1)
|
| 860 |
+
(book1,) = saved
|
| 861 |
+
self.assertEqual(book1.pk, 77777)
|
| 862 |
+
|
| 863 |
+
book1 = author.bookwithcustompk_set.get()
|
| 864 |
+
self.assertEqual(book1.title, "Les Fleurs du Mal")
|
| 865 |
+
|
| 866 |
+
def test_inline_formsets_with_multi_table_inheritance(self):
|
| 867 |
+
# Test inline formsets where the inline-edited object uses multi-table
|
| 868 |
+
# inheritance, thus has a non AutoField yet auto-created primary key.
|
| 869 |
+
|
| 870 |
+
AuthorBooksFormSet3 = inlineformset_factory(
|
| 871 |
+
Author, AlternateBook, can_delete=False, extra=1, fields="__all__"
|
| 872 |
+
)
|
| 873 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 874 |
+
|
| 875 |
+
formset = AuthorBooksFormSet3(instance=author)
|
| 876 |
+
self.assertEqual(len(formset.forms), 1)
|
| 877 |
+
self.assertHTMLEqual(
|
| 878 |
+
formset.forms[0].as_p(),
|
| 879 |
+
'<p><label for="id_alternatebook_set-0-title">Title:</label>'
|
| 880 |
+
'<input id="id_alternatebook_set-0-title" type="text" '
|
| 881 |
+
'name="alternatebook_set-0-title" maxlength="100"></p>'
|
| 882 |
+
'<p><label for="id_alternatebook_set-0-notes">Notes:</label>'
|
| 883 |
+
'<input id="id_alternatebook_set-0-notes" type="text" '
|
| 884 |
+
'name="alternatebook_set-0-notes" maxlength="100">'
|
| 885 |
+
'<input type="hidden" name="alternatebook_set-0-author" value="1" '
|
| 886 |
+
'id="id_alternatebook_set-0-author">'
|
| 887 |
+
'<input type="hidden" name="alternatebook_set-0-book_ptr" '
|
| 888 |
+
'id="id_alternatebook_set-0-book_ptr"></p>',
|
| 889 |
+
)
|
| 890 |
+
|
| 891 |
+
data = {
|
| 892 |
+
# The number of forms rendered.
|
| 893 |
+
"alternatebook_set-TOTAL_FORMS": "1",
|
| 894 |
+
# The number of forms with initial data.
|
| 895 |
+
"alternatebook_set-INITIAL_FORMS": "0",
|
| 896 |
+
# The max number of forms.
|
| 897 |
+
"alternatebook_set-MAX_NUM_FORMS": "",
|
| 898 |
+
"alternatebook_set-0-title": "Flowers of Evil",
|
| 899 |
+
"alternatebook_set-0-notes": "English translation of Les Fleurs du Mal",
|
| 900 |
+
}
|
| 901 |
+
|
| 902 |
+
formset = AuthorBooksFormSet3(data, instance=author)
|
| 903 |
+
self.assertTrue(formset.is_valid())
|
| 904 |
+
|
| 905 |
+
saved = formset.save()
|
| 906 |
+
self.assertEqual(len(saved), 1)
|
| 907 |
+
(book1,) = saved
|
| 908 |
+
self.assertEqual(book1.title, "Flowers of Evil")
|
| 909 |
+
self.assertEqual(book1.notes, "English translation of Les Fleurs du Mal")
|
| 910 |
+
|
| 911 |
+
@skipUnlessDBFeature("supports_partially_nullable_unique_constraints")
|
| 912 |
+
def test_inline_formsets_with_nullable_unique_together(self):
|
| 913 |
+
# Test inline formsets where the inline-edited object has a
|
| 914 |
+
# unique_together constraint with a nullable member
|
| 915 |
+
|
| 916 |
+
AuthorBooksFormSet4 = inlineformset_factory(
|
| 917 |
+
Author,
|
| 918 |
+
BookWithOptionalAltEditor,
|
| 919 |
+
can_delete=False,
|
| 920 |
+
extra=2,
|
| 921 |
+
fields="__all__",
|
| 922 |
+
)
|
| 923 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 924 |
+
|
| 925 |
+
data = {
|
| 926 |
+
# The number of forms rendered.
|
| 927 |
+
"bookwithoptionalalteditor_set-TOTAL_FORMS": "2",
|
| 928 |
+
# The number of forms with initial data.
|
| 929 |
+
"bookwithoptionalalteditor_set-INITIAL_FORMS": "0",
|
| 930 |
+
# The max number of forms.
|
| 931 |
+
"bookwithoptionalalteditor_set-MAX_NUM_FORMS": "",
|
| 932 |
+
"bookwithoptionalalteditor_set-0-author": "1",
|
| 933 |
+
"bookwithoptionalalteditor_set-0-title": "Les Fleurs du Mal",
|
| 934 |
+
"bookwithoptionalalteditor_set-1-author": "1",
|
| 935 |
+
"bookwithoptionalalteditor_set-1-title": "Les Fleurs du Mal",
|
| 936 |
+
}
|
| 937 |
+
formset = AuthorBooksFormSet4(data, instance=author)
|
| 938 |
+
self.assertTrue(formset.is_valid())
|
| 939 |
+
|
| 940 |
+
saved = formset.save()
|
| 941 |
+
self.assertEqual(len(saved), 2)
|
| 942 |
+
book1, book2 = saved
|
| 943 |
+
self.assertEqual(book1.author_id, 1)
|
| 944 |
+
self.assertEqual(book1.title, "Les Fleurs du Mal")
|
| 945 |
+
self.assertEqual(book2.author_id, 1)
|
| 946 |
+
self.assertEqual(book2.title, "Les Fleurs du Mal")
|
| 947 |
+
|
| 948 |
+
def test_inline_formsets_with_custom_save_method(self):
|
| 949 |
+
AuthorBooksFormSet = inlineformset_factory(
|
| 950 |
+
Author, Book, can_delete=False, extra=2, fields="__all__"
|
| 951 |
+
)
|
| 952 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 953 |
+
book1 = Book.objects.create(
|
| 954 |
+
pk=1, author=author, title="Les Paradis Artificiels"
|
| 955 |
+
)
|
| 956 |
+
book2 = Book.objects.create(pk=2, author=author, title="Les Fleurs du Mal")
|
| 957 |
+
book3 = Book.objects.create(pk=3, author=author, title="Flowers of Evil")
|
| 958 |
+
|
| 959 |
+
class PoemForm(forms.ModelForm):
|
| 960 |
+
def save(self, commit=True):
|
| 961 |
+
# change the name to "Brooklyn Bridge" just to be a jerk.
|
| 962 |
+
poem = super().save(commit=False)
|
| 963 |
+
poem.name = "Brooklyn Bridge"
|
| 964 |
+
if commit:
|
| 965 |
+
poem.save()
|
| 966 |
+
return poem
|
| 967 |
+
|
| 968 |
+
PoemFormSet = inlineformset_factory(Poet, Poem, form=PoemForm, fields="__all__")
|
| 969 |
+
|
| 970 |
+
data = {
|
| 971 |
+
"poem_set-TOTAL_FORMS": "3", # the number of forms rendered
|
| 972 |
+
"poem_set-INITIAL_FORMS": "0", # the number of forms with initial data
|
| 973 |
+
"poem_set-MAX_NUM_FORMS": "", # the max number of forms
|
| 974 |
+
"poem_set-0-name": "The Cloud in Trousers",
|
| 975 |
+
"poem_set-1-name": "I",
|
| 976 |
+
"poem_set-2-name": "",
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
poet = Poet.objects.create(name="Vladimir Mayakovsky")
|
| 980 |
+
formset = PoemFormSet(data=data, instance=poet)
|
| 981 |
+
self.assertTrue(formset.is_valid())
|
| 982 |
+
|
| 983 |
+
saved = formset.save()
|
| 984 |
+
self.assertEqual(len(saved), 2)
|
| 985 |
+
poem1, poem2 = saved
|
| 986 |
+
self.assertEqual(poem1.name, "Brooklyn Bridge")
|
| 987 |
+
self.assertEqual(poem2.name, "Brooklyn Bridge")
|
| 988 |
+
|
| 989 |
+
# We can provide a custom queryset to our InlineFormSet:
|
| 990 |
+
|
| 991 |
+
custom_qs = Book.objects.order_by("-title")
|
| 992 |
+
formset = AuthorBooksFormSet(instance=author, queryset=custom_qs)
|
| 993 |
+
self.assertEqual(len(formset.forms), 5)
|
| 994 |
+
self.assertHTMLEqual(
|
| 995 |
+
formset.forms[0].as_p(),
|
| 996 |
+
'<p><label for="id_book_set-0-title">Title:</label>'
|
| 997 |
+
'<input id="id_book_set-0-title" type="text" name="book_set-0-title" '
|
| 998 |
+
'value="Les Paradis Artificiels" maxlength="100">'
|
| 999 |
+
'<input type="hidden" name="book_set-0-author" value="1" '
|
| 1000 |
+
'id="id_book_set-0-author">'
|
| 1001 |
+
'<input type="hidden" name="book_set-0-id" value="1" id="id_book_set-0-id">'
|
| 1002 |
+
"</p>",
|
| 1003 |
+
)
|
| 1004 |
+
self.assertHTMLEqual(
|
| 1005 |
+
formset.forms[1].as_p(),
|
| 1006 |
+
'<p><label for="id_book_set-1-title">Title:</label>'
|
| 1007 |
+
'<input id="id_book_set-1-title" type="text" name="book_set-1-title" '
|
| 1008 |
+
'value="Les Fleurs du Mal" maxlength="100">'
|
| 1009 |
+
'<input type="hidden" name="book_set-1-author" value="1" '
|
| 1010 |
+
'id="id_book_set-1-author">'
|
| 1011 |
+
'<input type="hidden" name="book_set-1-id" value="2" id="id_book_set-1-id">'
|
| 1012 |
+
"</p>",
|
| 1013 |
+
)
|
| 1014 |
+
self.assertHTMLEqual(
|
| 1015 |
+
formset.forms[2].as_p(),
|
| 1016 |
+
'<p><label for="id_book_set-2-title">Title:</label>'
|
| 1017 |
+
'<input id="id_book_set-2-title" type="text" name="book_set-2-title" '
|
| 1018 |
+
'value="Flowers of Evil" maxlength="100">'
|
| 1019 |
+
'<input type="hidden" name="book_set-2-author" value="1" '
|
| 1020 |
+
'id="id_book_set-2-author">'
|
| 1021 |
+
'<input type="hidden" name="book_set-2-id" value="3" '
|
| 1022 |
+
'id="id_book_set-2-id"></p>',
|
| 1023 |
+
)
|
| 1024 |
+
self.assertHTMLEqual(
|
| 1025 |
+
formset.forms[3].as_p(),
|
| 1026 |
+
'<p><label for="id_book_set-3-title">Title:</label>'
|
| 1027 |
+
'<input id="id_book_set-3-title" type="text" name="book_set-3-title" '
|
| 1028 |
+
'maxlength="100">'
|
| 1029 |
+
'<input type="hidden" name="book_set-3-author" value="1" '
|
| 1030 |
+
'id="id_book_set-3-author">'
|
| 1031 |
+
'<input type="hidden" name="book_set-3-id" id="id_book_set-3-id"></p>',
|
| 1032 |
+
)
|
| 1033 |
+
self.assertHTMLEqual(
|
| 1034 |
+
formset.forms[4].as_p(),
|
| 1035 |
+
'<p><label for="id_book_set-4-title">Title:</label>'
|
| 1036 |
+
'<input id="id_book_set-4-title" type="text" name="book_set-4-title" '
|
| 1037 |
+
'maxlength="100">'
|
| 1038 |
+
'<input type="hidden" name="book_set-4-author" value="1" '
|
| 1039 |
+
'id="id_book_set-4-author">'
|
| 1040 |
+
'<input type="hidden" name="book_set-4-id" id="id_book_set-4-id"></p>',
|
| 1041 |
+
)
|
| 1042 |
+
|
| 1043 |
+
data = {
|
| 1044 |
+
"book_set-TOTAL_FORMS": "5", # the number of forms rendered
|
| 1045 |
+
"book_set-INITIAL_FORMS": "3", # the number of forms with initial data
|
| 1046 |
+
"book_set-MAX_NUM_FORMS": "", # the max number of forms
|
| 1047 |
+
"book_set-0-id": str(book1.id),
|
| 1048 |
+
"book_set-0-title": "Les Paradis Artificiels",
|
| 1049 |
+
"book_set-1-id": str(book2.id),
|
| 1050 |
+
"book_set-1-title": "Les Fleurs du Mal",
|
| 1051 |
+
"book_set-2-id": str(book3.id),
|
| 1052 |
+
"book_set-2-title": "Flowers of Evil",
|
| 1053 |
+
"book_set-3-title": "Revue des deux mondes",
|
| 1054 |
+
"book_set-4-title": "",
|
| 1055 |
+
}
|
| 1056 |
+
formset = AuthorBooksFormSet(data, instance=author, queryset=custom_qs)
|
| 1057 |
+
self.assertTrue(formset.is_valid())
|
| 1058 |
+
|
| 1059 |
+
custom_qs = Book.objects.filter(title__startswith="F")
|
| 1060 |
+
formset = AuthorBooksFormSet(instance=author, queryset=custom_qs)
|
| 1061 |
+
self.assertHTMLEqual(
|
| 1062 |
+
formset.forms[0].as_p(),
|
| 1063 |
+
'<p><label for="id_book_set-0-title">Title:</label>'
|
| 1064 |
+
'<input id="id_book_set-0-title" type="text" name="book_set-0-title" '
|
| 1065 |
+
'value="Flowers of Evil" maxlength="100">'
|
| 1066 |
+
'<input type="hidden" name="book_set-0-author" value="1" '
|
| 1067 |
+
'id="id_book_set-0-author">'
|
| 1068 |
+
'<input type="hidden" name="book_set-0-id" value="3" '
|
| 1069 |
+
'id="id_book_set-0-id"></p>',
|
| 1070 |
+
)
|
| 1071 |
+
self.assertHTMLEqual(
|
| 1072 |
+
formset.forms[1].as_p(),
|
| 1073 |
+
'<p><label for="id_book_set-1-title">Title:</label>'
|
| 1074 |
+
'<input id="id_book_set-1-title" type="text" name="book_set-1-title" '
|
| 1075 |
+
'maxlength="100">'
|
| 1076 |
+
'<input type="hidden" name="book_set-1-author" value="1" '
|
| 1077 |
+
'id="id_book_set-1-author">'
|
| 1078 |
+
'<input type="hidden" name="book_set-1-id" id="id_book_set-1-id"></p>',
|
| 1079 |
+
)
|
| 1080 |
+
self.assertHTMLEqual(
|
| 1081 |
+
formset.forms[2].as_p(),
|
| 1082 |
+
'<p><label for="id_book_set-2-title">Title:</label>'
|
| 1083 |
+
'<input id="id_book_set-2-title" type="text" name="book_set-2-title" '
|
| 1084 |
+
'maxlength="100">'
|
| 1085 |
+
'<input type="hidden" name="book_set-2-author" value="1" '
|
| 1086 |
+
'id="id_book_set-2-author">'
|
| 1087 |
+
'<input type="hidden" name="book_set-2-id" id="id_book_set-2-id"></p>',
|
| 1088 |
+
)
|
| 1089 |
+
|
| 1090 |
+
data = {
|
| 1091 |
+
"book_set-TOTAL_FORMS": "3", # the number of forms rendered
|
| 1092 |
+
"book_set-INITIAL_FORMS": "1", # the number of forms with initial data
|
| 1093 |
+
"book_set-MAX_NUM_FORMS": "", # the max number of forms
|
| 1094 |
+
"book_set-0-id": str(book3.id),
|
| 1095 |
+
"book_set-0-title": "Flowers of Evil",
|
| 1096 |
+
"book_set-1-title": "Revue des deux mondes",
|
| 1097 |
+
"book_set-2-title": "",
|
| 1098 |
+
}
|
| 1099 |
+
formset = AuthorBooksFormSet(data, instance=author, queryset=custom_qs)
|
| 1100 |
+
self.assertTrue(formset.is_valid())
|
| 1101 |
+
|
| 1102 |
+
def test_inline_formsets_with_custom_save_method_related_instance(self):
|
| 1103 |
+
"""
|
| 1104 |
+
The ModelForm.save() method should be able to access the related object
|
| 1105 |
+
if it exists in the database (#24395).
|
| 1106 |
+
"""
|
| 1107 |
+
|
| 1108 |
+
class PoemForm2(forms.ModelForm):
|
| 1109 |
+
def save(self, commit=True):
|
| 1110 |
+
poem = super().save(commit=False)
|
| 1111 |
+
poem.name = "%s by %s" % (poem.name, poem.poet.name)
|
| 1112 |
+
if commit:
|
| 1113 |
+
poem.save()
|
| 1114 |
+
return poem
|
| 1115 |
+
|
| 1116 |
+
PoemFormSet = inlineformset_factory(
|
| 1117 |
+
Poet, Poem, form=PoemForm2, fields="__all__"
|
| 1118 |
+
)
|
| 1119 |
+
data = {
|
| 1120 |
+
"poem_set-TOTAL_FORMS": "1",
|
| 1121 |
+
"poem_set-INITIAL_FORMS": "0",
|
| 1122 |
+
"poem_set-MAX_NUM_FORMS": "",
|
| 1123 |
+
"poem_set-0-name": "Le Lac",
|
| 1124 |
+
}
|
| 1125 |
+
poet = Poet()
|
| 1126 |
+
formset = PoemFormSet(data=data, instance=poet)
|
| 1127 |
+
self.assertTrue(formset.is_valid())
|
| 1128 |
+
|
| 1129 |
+
# The Poet instance is saved after the formset instantiation. This
|
| 1130 |
+
# happens in admin's changeform_view() when adding a new object and
|
| 1131 |
+
# some inlines in the same request.
|
| 1132 |
+
poet.name = "Lamartine"
|
| 1133 |
+
poet.save()
|
| 1134 |
+
poem = formset.save()[0]
|
| 1135 |
+
self.assertEqual(poem.name, "Le Lac by Lamartine")
|
| 1136 |
+
|
| 1137 |
+
def test_inline_formsets_with_wrong_fk_name(self):
|
| 1138 |
+
"""Regression for #23451"""
|
| 1139 |
+
message = "fk_name 'title' is not a ForeignKey to 'model_formsets.Author'."
|
| 1140 |
+
with self.assertRaisesMessage(ValueError, message):
|
| 1141 |
+
inlineformset_factory(Author, Book, fields="__all__", fk_name="title")
|
| 1142 |
+
|
| 1143 |
+
def test_custom_pk(self):
|
| 1144 |
+
# We need to ensure that it is displayed
|
| 1145 |
+
|
| 1146 |
+
CustomPrimaryKeyFormSet = modelformset_factory(
|
| 1147 |
+
CustomPrimaryKey, fields="__all__"
|
| 1148 |
+
)
|
| 1149 |
+
formset = CustomPrimaryKeyFormSet()
|
| 1150 |
+
self.assertEqual(len(formset.forms), 1)
|
| 1151 |
+
self.assertHTMLEqual(
|
| 1152 |
+
formset.forms[0].as_p(),
|
| 1153 |
+
'<p><label for="id_form-0-my_pk">My pk:</label>'
|
| 1154 |
+
'<input id="id_form-0-my_pk" type="text" name="form-0-my_pk" '
|
| 1155 |
+
'maxlength="10"></p>'
|
| 1156 |
+
'<p><label for="id_form-0-some_field">Some field:</label>'
|
| 1157 |
+
'<input id="id_form-0-some_field" type="text" name="form-0-some_field" '
|
| 1158 |
+
'maxlength="100"></p>',
|
| 1159 |
+
)
|
| 1160 |
+
|
| 1161 |
+
# Custom primary keys with ForeignKey, OneToOneField and AutoField ############
|
| 1162 |
+
|
| 1163 |
+
place = Place.objects.create(pk=1, name="Giordanos", city="Chicago")
|
| 1164 |
+
|
| 1165 |
+
FormSet = inlineformset_factory(
|
| 1166 |
+
Place, Owner, extra=2, can_delete=False, fields="__all__"
|
| 1167 |
+
)
|
| 1168 |
+
formset = FormSet(instance=place)
|
| 1169 |
+
self.assertEqual(len(formset.forms), 2)
|
| 1170 |
+
self.assertHTMLEqual(
|
| 1171 |
+
formset.forms[0].as_p(),
|
| 1172 |
+
'<p><label for="id_owner_set-0-name">Name:</label>'
|
| 1173 |
+
'<input id="id_owner_set-0-name" type="text" name="owner_set-0-name" '
|
| 1174 |
+
'maxlength="100">'
|
| 1175 |
+
'<input type="hidden" name="owner_set-0-place" value="1" '
|
| 1176 |
+
'id="id_owner_set-0-place">'
|
| 1177 |
+
'<input type="hidden" name="owner_set-0-auto_id" '
|
| 1178 |
+
'id="id_owner_set-0-auto_id"></p>',
|
| 1179 |
+
)
|
| 1180 |
+
self.assertHTMLEqual(
|
| 1181 |
+
formset.forms[1].as_p(),
|
| 1182 |
+
'<p><label for="id_owner_set-1-name">Name:</label>'
|
| 1183 |
+
'<input id="id_owner_set-1-name" type="text" name="owner_set-1-name" '
|
| 1184 |
+
'maxlength="100">'
|
| 1185 |
+
'<input type="hidden" name="owner_set-1-place" value="1" '
|
| 1186 |
+
'id="id_owner_set-1-place">'
|
| 1187 |
+
'<input type="hidden" name="owner_set-1-auto_id" '
|
| 1188 |
+
'id="id_owner_set-1-auto_id"></p>',
|
| 1189 |
+
)
|
| 1190 |
+
|
| 1191 |
+
data = {
|
| 1192 |
+
"owner_set-TOTAL_FORMS": "2",
|
| 1193 |
+
"owner_set-INITIAL_FORMS": "0",
|
| 1194 |
+
"owner_set-MAX_NUM_FORMS": "",
|
| 1195 |
+
"owner_set-0-auto_id": "",
|
| 1196 |
+
"owner_set-0-name": "Joe Perry",
|
| 1197 |
+
"owner_set-1-auto_id": "",
|
| 1198 |
+
"owner_set-1-name": "",
|
| 1199 |
+
}
|
| 1200 |
+
formset = FormSet(data, instance=place)
|
| 1201 |
+
self.assertTrue(formset.is_valid())
|
| 1202 |
+
saved = formset.save()
|
| 1203 |
+
self.assertEqual(len(saved), 1)
|
| 1204 |
+
(owner1,) = saved
|
| 1205 |
+
self.assertEqual(owner1.name, "Joe Perry")
|
| 1206 |
+
self.assertEqual(owner1.place.name, "Giordanos")
|
| 1207 |
+
|
| 1208 |
+
formset = FormSet(instance=place)
|
| 1209 |
+
self.assertEqual(len(formset.forms), 3)
|
| 1210 |
+
self.assertHTMLEqual(
|
| 1211 |
+
formset.forms[0].as_p(),
|
| 1212 |
+
'<p><label for="id_owner_set-0-name">Name:</label>'
|
| 1213 |
+
'<input id="id_owner_set-0-name" type="text" name="owner_set-0-name" '
|
| 1214 |
+
'value="Joe Perry" maxlength="100">'
|
| 1215 |
+
'<input type="hidden" name="owner_set-0-place" value="1" '
|
| 1216 |
+
'id="id_owner_set-0-place">'
|
| 1217 |
+
'<input type="hidden" name="owner_set-0-auto_id" value="%d" '
|
| 1218 |
+
'id="id_owner_set-0-auto_id"></p>' % owner1.auto_id,
|
| 1219 |
+
)
|
| 1220 |
+
self.assertHTMLEqual(
|
| 1221 |
+
formset.forms[1].as_p(),
|
| 1222 |
+
'<p><label for="id_owner_set-1-name">Name:</label>'
|
| 1223 |
+
'<input id="id_owner_set-1-name" type="text" name="owner_set-1-name" '
|
| 1224 |
+
'maxlength="100">'
|
| 1225 |
+
'<input type="hidden" name="owner_set-1-place" value="1" '
|
| 1226 |
+
'id="id_owner_set-1-place">'
|
| 1227 |
+
'<input type="hidden" name="owner_set-1-auto_id" '
|
| 1228 |
+
'id="id_owner_set-1-auto_id"></p>',
|
| 1229 |
+
)
|
| 1230 |
+
self.assertHTMLEqual(
|
| 1231 |
+
formset.forms[2].as_p(),
|
| 1232 |
+
'<p><label for="id_owner_set-2-name">Name:</label>'
|
| 1233 |
+
'<input id="id_owner_set-2-name" type="text" name="owner_set-2-name" '
|
| 1234 |
+
'maxlength="100">'
|
| 1235 |
+
'<input type="hidden" name="owner_set-2-place" value="1" '
|
| 1236 |
+
'id="id_owner_set-2-place">'
|
| 1237 |
+
'<input type="hidden" name="owner_set-2-auto_id" '
|
| 1238 |
+
'id="id_owner_set-2-auto_id"></p>',
|
| 1239 |
+
)
|
| 1240 |
+
|
| 1241 |
+
data = {
|
| 1242 |
+
"owner_set-TOTAL_FORMS": "3",
|
| 1243 |
+
"owner_set-INITIAL_FORMS": "1",
|
| 1244 |
+
"owner_set-MAX_NUM_FORMS": "",
|
| 1245 |
+
"owner_set-0-auto_id": str(owner1.auto_id),
|
| 1246 |
+
"owner_set-0-name": "Joe Perry",
|
| 1247 |
+
"owner_set-1-auto_id": "",
|
| 1248 |
+
"owner_set-1-name": "Jack Berry",
|
| 1249 |
+
"owner_set-2-auto_id": "",
|
| 1250 |
+
"owner_set-2-name": "",
|
| 1251 |
+
}
|
| 1252 |
+
formset = FormSet(data, instance=place)
|
| 1253 |
+
self.assertTrue(formset.is_valid())
|
| 1254 |
+
saved = formset.save()
|
| 1255 |
+
self.assertEqual(len(saved), 1)
|
| 1256 |
+
(owner2,) = saved
|
| 1257 |
+
self.assertEqual(owner2.name, "Jack Berry")
|
| 1258 |
+
self.assertEqual(owner2.place.name, "Giordanos")
|
| 1259 |
+
|
| 1260 |
+
# A custom primary key that is a ForeignKey or OneToOneField get
|
| 1261 |
+
# rendered for the user to choose.
|
| 1262 |
+
FormSet = modelformset_factory(OwnerProfile, fields="__all__")
|
| 1263 |
+
formset = FormSet()
|
| 1264 |
+
self.assertHTMLEqual(
|
| 1265 |
+
formset.forms[0].as_p(),
|
| 1266 |
+
'<p><label for="id_form-0-owner">Owner:</label>'
|
| 1267 |
+
'<select name="form-0-owner" id="id_form-0-owner">'
|
| 1268 |
+
'<option value="" selected>---------</option>'
|
| 1269 |
+
'<option value="%d">Joe Perry at Giordanos</option>'
|
| 1270 |
+
'<option value="%d">Jack Berry at Giordanos</option>'
|
| 1271 |
+
"</select></p>"
|
| 1272 |
+
'<p><label for="id_form-0-age">Age:</label>'
|
| 1273 |
+
'<input type="number" name="form-0-age" id="id_form-0-age" min="0"></p>'
|
| 1274 |
+
% (owner1.auto_id, owner2.auto_id),
|
| 1275 |
+
)
|
| 1276 |
+
|
| 1277 |
+
owner1 = Owner.objects.get(name="Joe Perry")
|
| 1278 |
+
FormSet = inlineformset_factory(
|
| 1279 |
+
Owner, OwnerProfile, max_num=1, can_delete=False, fields="__all__"
|
| 1280 |
+
)
|
| 1281 |
+
self.assertEqual(FormSet.max_num, 1)
|
| 1282 |
+
|
| 1283 |
+
formset = FormSet(instance=owner1)
|
| 1284 |
+
self.assertEqual(len(formset.forms), 1)
|
| 1285 |
+
self.assertHTMLEqual(
|
| 1286 |
+
formset.forms[0].as_p(),
|
| 1287 |
+
'<p><label for="id_ownerprofile-0-age">Age:</label>'
|
| 1288 |
+
'<input type="number" name="ownerprofile-0-age" '
|
| 1289 |
+
'id="id_ownerprofile-0-age" min="0">'
|
| 1290 |
+
'<input type="hidden" name="ownerprofile-0-owner" value="%d" '
|
| 1291 |
+
'id="id_ownerprofile-0-owner"></p>' % owner1.auto_id,
|
| 1292 |
+
)
|
| 1293 |
+
|
| 1294 |
+
data = {
|
| 1295 |
+
"ownerprofile-TOTAL_FORMS": "1",
|
| 1296 |
+
"ownerprofile-INITIAL_FORMS": "0",
|
| 1297 |
+
"ownerprofile-MAX_NUM_FORMS": "1",
|
| 1298 |
+
"ownerprofile-0-owner": "",
|
| 1299 |
+
"ownerprofile-0-age": "54",
|
| 1300 |
+
}
|
| 1301 |
+
formset = FormSet(data, instance=owner1)
|
| 1302 |
+
self.assertTrue(formset.is_valid())
|
| 1303 |
+
saved = formset.save()
|
| 1304 |
+
self.assertEqual(len(saved), 1)
|
| 1305 |
+
(profile1,) = saved
|
| 1306 |
+
self.assertEqual(profile1.owner, owner1)
|
| 1307 |
+
self.assertEqual(profile1.age, 54)
|
| 1308 |
+
|
| 1309 |
+
formset = FormSet(instance=owner1)
|
| 1310 |
+
self.assertEqual(len(formset.forms), 1)
|
| 1311 |
+
self.assertHTMLEqual(
|
| 1312 |
+
formset.forms[0].as_p(),
|
| 1313 |
+
'<p><label for="id_ownerprofile-0-age">Age:</label>'
|
| 1314 |
+
'<input type="number" name="ownerprofile-0-age" value="54" '
|
| 1315 |
+
'id="id_ownerprofile-0-age" min="0">'
|
| 1316 |
+
'<input type="hidden" name="ownerprofile-0-owner" value="%d" '
|
| 1317 |
+
'id="id_ownerprofile-0-owner"></p>' % owner1.auto_id,
|
| 1318 |
+
)
|
| 1319 |
+
|
| 1320 |
+
data = {
|
| 1321 |
+
"ownerprofile-TOTAL_FORMS": "1",
|
| 1322 |
+
"ownerprofile-INITIAL_FORMS": "1",
|
| 1323 |
+
"ownerprofile-MAX_NUM_FORMS": "1",
|
| 1324 |
+
"ownerprofile-0-owner": str(owner1.auto_id),
|
| 1325 |
+
"ownerprofile-0-age": "55",
|
| 1326 |
+
}
|
| 1327 |
+
formset = FormSet(data, instance=owner1)
|
| 1328 |
+
self.assertTrue(formset.is_valid())
|
| 1329 |
+
saved = formset.save()
|
| 1330 |
+
self.assertEqual(len(saved), 1)
|
| 1331 |
+
(profile1,) = saved
|
| 1332 |
+
self.assertEqual(profile1.owner, owner1)
|
| 1333 |
+
self.assertEqual(profile1.age, 55)
|
| 1334 |
+
|
| 1335 |
+
def test_unique_true_enforces_max_num_one(self):
|
| 1336 |
+
# ForeignKey with unique=True should enforce max_num=1
|
| 1337 |
+
|
| 1338 |
+
place = Place.objects.create(pk=1, name="Giordanos", city="Chicago")
|
| 1339 |
+
|
| 1340 |
+
FormSet = inlineformset_factory(
|
| 1341 |
+
Place, Location, can_delete=False, fields="__all__"
|
| 1342 |
+
)
|
| 1343 |
+
self.assertEqual(FormSet.max_num, 1)
|
| 1344 |
+
|
| 1345 |
+
formset = FormSet(instance=place)
|
| 1346 |
+
self.assertEqual(len(formset.forms), 1)
|
| 1347 |
+
self.assertHTMLEqual(
|
| 1348 |
+
formset.forms[0].as_p(),
|
| 1349 |
+
'<p><label for="id_location_set-0-lat">Lat:</label>'
|
| 1350 |
+
'<input id="id_location_set-0-lat" type="text" name="location_set-0-lat" '
|
| 1351 |
+
'maxlength="100"></p>'
|
| 1352 |
+
'<p><label for="id_location_set-0-lon">Lon:</label>'
|
| 1353 |
+
'<input id="id_location_set-0-lon" type="text" name="location_set-0-lon" '
|
| 1354 |
+
'maxlength="100">'
|
| 1355 |
+
'<input type="hidden" name="location_set-0-place" value="1" '
|
| 1356 |
+
'id="id_location_set-0-place">'
|
| 1357 |
+
'<input type="hidden" name="location_set-0-id" '
|
| 1358 |
+
'id="id_location_set-0-id"></p>',
|
| 1359 |
+
)
|
| 1360 |
+
|
| 1361 |
+
def test_foreign_keys_in_parents(self):
|
| 1362 |
+
self.assertEqual(type(_get_foreign_key(Restaurant, Owner)), models.ForeignKey)
|
| 1363 |
+
self.assertEqual(
|
| 1364 |
+
type(_get_foreign_key(MexicanRestaurant, Owner)), models.ForeignKey
|
| 1365 |
+
)
|
| 1366 |
+
|
| 1367 |
+
def test_unique_validation(self):
|
| 1368 |
+
FormSet = modelformset_factory(Product, fields="__all__", extra=1)
|
| 1369 |
+
data = {
|
| 1370 |
+
"form-TOTAL_FORMS": "1",
|
| 1371 |
+
"form-INITIAL_FORMS": "0",
|
| 1372 |
+
"form-MAX_NUM_FORMS": "",
|
| 1373 |
+
"form-0-slug": "car-red",
|
| 1374 |
+
}
|
| 1375 |
+
formset = FormSet(data)
|
| 1376 |
+
self.assertTrue(formset.is_valid())
|
| 1377 |
+
saved = formset.save()
|
| 1378 |
+
self.assertEqual(len(saved), 1)
|
| 1379 |
+
(product1,) = saved
|
| 1380 |
+
self.assertEqual(product1.slug, "car-red")
|
| 1381 |
+
|
| 1382 |
+
data = {
|
| 1383 |
+
"form-TOTAL_FORMS": "1",
|
| 1384 |
+
"form-INITIAL_FORMS": "0",
|
| 1385 |
+
"form-MAX_NUM_FORMS": "",
|
| 1386 |
+
"form-0-slug": "car-red",
|
| 1387 |
+
}
|
| 1388 |
+
formset = FormSet(data)
|
| 1389 |
+
self.assertFalse(formset.is_valid())
|
| 1390 |
+
self.assertEqual(
|
| 1391 |
+
formset.errors, [{"slug": ["Product with this Slug already exists."]}]
|
| 1392 |
+
)
|
| 1393 |
+
|
| 1394 |
+
def test_modelformset_validate_max_flag(self):
|
| 1395 |
+
# If validate_max is set and max_num is less than TOTAL_FORMS in the
|
| 1396 |
+
# data, then throw an exception. MAX_NUM_FORMS in the data is
|
| 1397 |
+
# irrelevant here (it's output as a hint for the client but its
|
| 1398 |
+
# value in the returned data is not checked)
|
| 1399 |
+
|
| 1400 |
+
data = {
|
| 1401 |
+
"form-TOTAL_FORMS": "2",
|
| 1402 |
+
"form-INITIAL_FORMS": "0",
|
| 1403 |
+
"form-MAX_NUM_FORMS": "2", # should be ignored
|
| 1404 |
+
"form-0-price": "12.00",
|
| 1405 |
+
"form-0-quantity": "1",
|
| 1406 |
+
"form-1-price": "24.00",
|
| 1407 |
+
"form-1-quantity": "2",
|
| 1408 |
+
}
|
| 1409 |
+
|
| 1410 |
+
FormSet = modelformset_factory(
|
| 1411 |
+
Price, fields="__all__", extra=1, max_num=1, validate_max=True
|
| 1412 |
+
)
|
| 1413 |
+
formset = FormSet(data)
|
| 1414 |
+
self.assertFalse(formset.is_valid())
|
| 1415 |
+
self.assertEqual(formset.non_form_errors(), ["Please submit at most 1 form."])
|
| 1416 |
+
|
| 1417 |
+
# Now test the same thing without the validate_max flag to ensure
|
| 1418 |
+
# default behavior is unchanged
|
| 1419 |
+
FormSet = modelformset_factory(Price, fields="__all__", extra=1, max_num=1)
|
| 1420 |
+
formset = FormSet(data)
|
| 1421 |
+
self.assertTrue(formset.is_valid())
|
| 1422 |
+
|
| 1423 |
+
def test_modelformset_min_num_equals_max_num_less_than(self):
|
| 1424 |
+
data = {
|
| 1425 |
+
"form-TOTAL_FORMS": "3",
|
| 1426 |
+
"form-INITIAL_FORMS": "0",
|
| 1427 |
+
"form-MAX_NUM_FORMS": "2",
|
| 1428 |
+
"form-0-slug": "car-red",
|
| 1429 |
+
"form-1-slug": "car-blue",
|
| 1430 |
+
"form-2-slug": "car-black",
|
| 1431 |
+
}
|
| 1432 |
+
FormSet = modelformset_factory(
|
| 1433 |
+
Product,
|
| 1434 |
+
fields="__all__",
|
| 1435 |
+
extra=1,
|
| 1436 |
+
max_num=2,
|
| 1437 |
+
validate_max=True,
|
| 1438 |
+
min_num=2,
|
| 1439 |
+
validate_min=True,
|
| 1440 |
+
)
|
| 1441 |
+
formset = FormSet(data)
|
| 1442 |
+
self.assertFalse(formset.is_valid())
|
| 1443 |
+
self.assertEqual(formset.non_form_errors(), ["Please submit at most 2 forms."])
|
| 1444 |
+
|
| 1445 |
+
def test_modelformset_min_num_equals_max_num_more_than(self):
|
| 1446 |
+
data = {
|
| 1447 |
+
"form-TOTAL_FORMS": "1",
|
| 1448 |
+
"form-INITIAL_FORMS": "0",
|
| 1449 |
+
"form-MAX_NUM_FORMS": "2",
|
| 1450 |
+
"form-0-slug": "car-red",
|
| 1451 |
+
}
|
| 1452 |
+
FormSet = modelformset_factory(
|
| 1453 |
+
Product,
|
| 1454 |
+
fields="__all__",
|
| 1455 |
+
extra=1,
|
| 1456 |
+
max_num=2,
|
| 1457 |
+
validate_max=True,
|
| 1458 |
+
min_num=2,
|
| 1459 |
+
validate_min=True,
|
| 1460 |
+
)
|
| 1461 |
+
formset = FormSet(data)
|
| 1462 |
+
self.assertFalse(formset.is_valid())
|
| 1463 |
+
self.assertEqual(formset.non_form_errors(), ["Please submit at least 2 forms."])
|
| 1464 |
+
|
| 1465 |
+
def test_unique_together_validation(self):
|
| 1466 |
+
FormSet = modelformset_factory(Price, fields="__all__", extra=1)
|
| 1467 |
+
data = {
|
| 1468 |
+
"form-TOTAL_FORMS": "1",
|
| 1469 |
+
"form-INITIAL_FORMS": "0",
|
| 1470 |
+
"form-MAX_NUM_FORMS": "",
|
| 1471 |
+
"form-0-price": "12.00",
|
| 1472 |
+
"form-0-quantity": "1",
|
| 1473 |
+
}
|
| 1474 |
+
formset = FormSet(data)
|
| 1475 |
+
self.assertTrue(formset.is_valid())
|
| 1476 |
+
saved = formset.save()
|
| 1477 |
+
self.assertEqual(len(saved), 1)
|
| 1478 |
+
(price1,) = saved
|
| 1479 |
+
self.assertEqual(price1.price, Decimal("12.00"))
|
| 1480 |
+
self.assertEqual(price1.quantity, 1)
|
| 1481 |
+
|
| 1482 |
+
data = {
|
| 1483 |
+
"form-TOTAL_FORMS": "1",
|
| 1484 |
+
"form-INITIAL_FORMS": "0",
|
| 1485 |
+
"form-MAX_NUM_FORMS": "",
|
| 1486 |
+
"form-0-price": "12.00",
|
| 1487 |
+
"form-0-quantity": "1",
|
| 1488 |
+
}
|
| 1489 |
+
formset = FormSet(data)
|
| 1490 |
+
self.assertFalse(formset.is_valid())
|
| 1491 |
+
self.assertEqual(
|
| 1492 |
+
formset.errors,
|
| 1493 |
+
[{"__all__": ["Price with this Price and Quantity already exists."]}],
|
| 1494 |
+
)
|
| 1495 |
+
|
| 1496 |
+
def test_unique_together_with_inlineformset_factory(self):
|
| 1497 |
+
# Also see bug #8882.
|
| 1498 |
+
|
| 1499 |
+
repository = Repository.objects.create(name="Test Repo")
|
| 1500 |
+
FormSet = inlineformset_factory(Repository, Revision, extra=1, fields="__all__")
|
| 1501 |
+
data = {
|
| 1502 |
+
"revision_set-TOTAL_FORMS": "1",
|
| 1503 |
+
"revision_set-INITIAL_FORMS": "0",
|
| 1504 |
+
"revision_set-MAX_NUM_FORMS": "",
|
| 1505 |
+
"revision_set-0-repository": repository.pk,
|
| 1506 |
+
"revision_set-0-revision": "146239817507f148d448db38840db7c3cbf47c76",
|
| 1507 |
+
"revision_set-0-DELETE": "",
|
| 1508 |
+
}
|
| 1509 |
+
formset = FormSet(data, instance=repository)
|
| 1510 |
+
self.assertTrue(formset.is_valid())
|
| 1511 |
+
saved = formset.save()
|
| 1512 |
+
self.assertEqual(len(saved), 1)
|
| 1513 |
+
(revision1,) = saved
|
| 1514 |
+
self.assertEqual(revision1.repository, repository)
|
| 1515 |
+
self.assertEqual(revision1.revision, "146239817507f148d448db38840db7c3cbf47c76")
|
| 1516 |
+
|
| 1517 |
+
# attempt to save the same revision against the same repo.
|
| 1518 |
+
data = {
|
| 1519 |
+
"revision_set-TOTAL_FORMS": "1",
|
| 1520 |
+
"revision_set-INITIAL_FORMS": "0",
|
| 1521 |
+
"revision_set-MAX_NUM_FORMS": "",
|
| 1522 |
+
"revision_set-0-repository": repository.pk,
|
| 1523 |
+
"revision_set-0-revision": "146239817507f148d448db38840db7c3cbf47c76",
|
| 1524 |
+
"revision_set-0-DELETE": "",
|
| 1525 |
+
}
|
| 1526 |
+
formset = FormSet(data, instance=repository)
|
| 1527 |
+
self.assertFalse(formset.is_valid())
|
| 1528 |
+
self.assertEqual(
|
| 1529 |
+
formset.errors,
|
| 1530 |
+
[
|
| 1531 |
+
{
|
| 1532 |
+
"__all__": [
|
| 1533 |
+
"Revision with this Repository and Revision already exists."
|
| 1534 |
+
]
|
| 1535 |
+
}
|
| 1536 |
+
],
|
| 1537 |
+
)
|
| 1538 |
+
|
| 1539 |
+
# unique_together with inlineformset_factory with overridden form fields
|
| 1540 |
+
# Also see #9494
|
| 1541 |
+
|
| 1542 |
+
FormSet = inlineformset_factory(
|
| 1543 |
+
Repository, Revision, fields=("revision",), extra=1
|
| 1544 |
+
)
|
| 1545 |
+
data = {
|
| 1546 |
+
"revision_set-TOTAL_FORMS": "1",
|
| 1547 |
+
"revision_set-INITIAL_FORMS": "0",
|
| 1548 |
+
"revision_set-MAX_NUM_FORMS": "",
|
| 1549 |
+
"revision_set-0-repository": repository.pk,
|
| 1550 |
+
"revision_set-0-revision": "146239817507f148d448db38840db7c3cbf47c76",
|
| 1551 |
+
"revision_set-0-DELETE": "",
|
| 1552 |
+
}
|
| 1553 |
+
formset = FormSet(data, instance=repository)
|
| 1554 |
+
self.assertFalse(formset.is_valid())
|
| 1555 |
+
|
| 1556 |
+
def test_callable_defaults(self):
|
| 1557 |
+
# Use of callable defaults (see bug #7975).
|
| 1558 |
+
|
| 1559 |
+
person = Person.objects.create(name="Ringo")
|
| 1560 |
+
FormSet = inlineformset_factory(
|
| 1561 |
+
Person, Membership, can_delete=False, extra=1, fields="__all__"
|
| 1562 |
+
)
|
| 1563 |
+
formset = FormSet(instance=person)
|
| 1564 |
+
|
| 1565 |
+
# Django will render a hidden field for model fields that have a callable
|
| 1566 |
+
# default. This is required to ensure the value is tested for change correctly
|
| 1567 |
+
# when determine what extra forms have changed to save.
|
| 1568 |
+
|
| 1569 |
+
self.assertEqual(len(formset.forms), 1) # this formset only has one form
|
| 1570 |
+
form = formset.forms[0]
|
| 1571 |
+
now = form.fields["date_joined"].initial()
|
| 1572 |
+
result = form.as_p()
|
| 1573 |
+
result = re.sub(
|
| 1574 |
+
r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?",
|
| 1575 |
+
"__DATETIME__",
|
| 1576 |
+
result,
|
| 1577 |
+
)
|
| 1578 |
+
self.assertHTMLEqual(
|
| 1579 |
+
result,
|
| 1580 |
+
'<p><label for="id_membership_set-0-date_joined">Date joined:</label>'
|
| 1581 |
+
'<input type="text" name="membership_set-0-date_joined" '
|
| 1582 |
+
'value="__DATETIME__" id="id_membership_set-0-date_joined">'
|
| 1583 |
+
'<input type="hidden" name="initial-membership_set-0-date_joined" '
|
| 1584 |
+
'value="__DATETIME__" '
|
| 1585 |
+
'id="initial-membership_set-0-id_membership_set-0-date_joined"></p>'
|
| 1586 |
+
'<p><label for="id_membership_set-0-karma">Karma:</label>'
|
| 1587 |
+
'<input type="number" name="membership_set-0-karma" '
|
| 1588 |
+
'id="id_membership_set-0-karma">'
|
| 1589 |
+
'<input type="hidden" name="membership_set-0-person" value="%d" '
|
| 1590 |
+
'id="id_membership_set-0-person">'
|
| 1591 |
+
'<input type="hidden" name="membership_set-0-id" '
|
| 1592 |
+
'id="id_membership_set-0-id"></p>' % person.id,
|
| 1593 |
+
)
|
| 1594 |
+
|
| 1595 |
+
# test for validation with callable defaults. Validations rely on hidden fields
|
| 1596 |
+
|
| 1597 |
+
data = {
|
| 1598 |
+
"membership_set-TOTAL_FORMS": "1",
|
| 1599 |
+
"membership_set-INITIAL_FORMS": "0",
|
| 1600 |
+
"membership_set-MAX_NUM_FORMS": "",
|
| 1601 |
+
"membership_set-0-date_joined": now.strftime("%Y-%m-%d %H:%M:%S"),
|
| 1602 |
+
"initial-membership_set-0-date_joined": now.strftime("%Y-%m-%d %H:%M:%S"),
|
| 1603 |
+
"membership_set-0-karma": "",
|
| 1604 |
+
}
|
| 1605 |
+
formset = FormSet(data, instance=person)
|
| 1606 |
+
self.assertTrue(formset.is_valid())
|
| 1607 |
+
|
| 1608 |
+
# now test for when the data changes
|
| 1609 |
+
|
| 1610 |
+
one_day_later = now + datetime.timedelta(days=1)
|
| 1611 |
+
filled_data = {
|
| 1612 |
+
"membership_set-TOTAL_FORMS": "1",
|
| 1613 |
+
"membership_set-INITIAL_FORMS": "0",
|
| 1614 |
+
"membership_set-MAX_NUM_FORMS": "",
|
| 1615 |
+
"membership_set-0-date_joined": one_day_later.strftime("%Y-%m-%d %H:%M:%S"),
|
| 1616 |
+
"initial-membership_set-0-date_joined": now.strftime("%Y-%m-%d %H:%M:%S"),
|
| 1617 |
+
"membership_set-0-karma": "",
|
| 1618 |
+
}
|
| 1619 |
+
formset = FormSet(filled_data, instance=person)
|
| 1620 |
+
self.assertFalse(formset.is_valid())
|
| 1621 |
+
|
| 1622 |
+
# now test with split datetime fields
|
| 1623 |
+
|
| 1624 |
+
class MembershipForm(forms.ModelForm):
|
| 1625 |
+
date_joined = forms.SplitDateTimeField(initial=now)
|
| 1626 |
+
|
| 1627 |
+
class Meta:
|
| 1628 |
+
model = Membership
|
| 1629 |
+
fields = "__all__"
|
| 1630 |
+
|
| 1631 |
+
def __init__(self, **kwargs):
|
| 1632 |
+
super().__init__(**kwargs)
|
| 1633 |
+
self.fields["date_joined"].widget = forms.SplitDateTimeWidget()
|
| 1634 |
+
|
| 1635 |
+
FormSet = inlineformset_factory(
|
| 1636 |
+
Person,
|
| 1637 |
+
Membership,
|
| 1638 |
+
form=MembershipForm,
|
| 1639 |
+
can_delete=False,
|
| 1640 |
+
extra=1,
|
| 1641 |
+
fields="__all__",
|
| 1642 |
+
)
|
| 1643 |
+
data = {
|
| 1644 |
+
"membership_set-TOTAL_FORMS": "1",
|
| 1645 |
+
"membership_set-INITIAL_FORMS": "0",
|
| 1646 |
+
"membership_set-MAX_NUM_FORMS": "",
|
| 1647 |
+
"membership_set-0-date_joined_0": now.strftime("%Y-%m-%d"),
|
| 1648 |
+
"membership_set-0-date_joined_1": now.strftime("%H:%M:%S"),
|
| 1649 |
+
"initial-membership_set-0-date_joined": now.strftime("%Y-%m-%d %H:%M:%S"),
|
| 1650 |
+
"membership_set-0-karma": "",
|
| 1651 |
+
}
|
| 1652 |
+
formset = FormSet(data, instance=person)
|
| 1653 |
+
self.assertTrue(formset.is_valid())
|
| 1654 |
+
|
| 1655 |
+
def test_inlineformset_factory_with_null_fk(self):
|
| 1656 |
+
# inlineformset_factory tests with fk having null=True. see #9462.
|
| 1657 |
+
# create some data that will exhibit the issue
|
| 1658 |
+
team = Team.objects.create(name="Red Vipers")
|
| 1659 |
+
Player(name="Timmy").save()
|
| 1660 |
+
Player(name="Bobby", team=team).save()
|
| 1661 |
+
|
| 1662 |
+
PlayerInlineFormSet = inlineformset_factory(Team, Player, fields="__all__")
|
| 1663 |
+
formset = PlayerInlineFormSet()
|
| 1664 |
+
self.assertQuerySetEqual(formset.get_queryset(), [])
|
| 1665 |
+
|
| 1666 |
+
formset = PlayerInlineFormSet(instance=team)
|
| 1667 |
+
players = formset.get_queryset()
|
| 1668 |
+
self.assertEqual(len(players), 1)
|
| 1669 |
+
(player1,) = players
|
| 1670 |
+
self.assertEqual(player1.team, team)
|
| 1671 |
+
self.assertEqual(player1.name, "Bobby")
|
| 1672 |
+
|
| 1673 |
+
def test_inlineformset_with_arrayfield(self):
|
| 1674 |
+
class SimpleArrayField(forms.CharField):
|
| 1675 |
+
"""A proxy for django.contrib.postgres.forms.SimpleArrayField."""
|
| 1676 |
+
|
| 1677 |
+
def to_python(self, value):
|
| 1678 |
+
value = super().to_python(value)
|
| 1679 |
+
return value.split(",") if value else []
|
| 1680 |
+
|
| 1681 |
+
class BookForm(forms.ModelForm):
|
| 1682 |
+
title = SimpleArrayField()
|
| 1683 |
+
|
| 1684 |
+
class Meta:
|
| 1685 |
+
model = Book
|
| 1686 |
+
fields = ("title",)
|
| 1687 |
+
|
| 1688 |
+
BookFormSet = inlineformset_factory(Author, Book, form=BookForm)
|
| 1689 |
+
data = {
|
| 1690 |
+
"book_set-TOTAL_FORMS": "3",
|
| 1691 |
+
"book_set-INITIAL_FORMS": "0",
|
| 1692 |
+
"book_set-MAX_NUM_FORMS": "",
|
| 1693 |
+
"book_set-0-title": "test1,test2",
|
| 1694 |
+
"book_set-1-title": "test1,test2",
|
| 1695 |
+
"book_set-2-title": "test3,test4",
|
| 1696 |
+
}
|
| 1697 |
+
author = Author.objects.create(name="test")
|
| 1698 |
+
formset = BookFormSet(data, instance=author)
|
| 1699 |
+
self.assertEqual(
|
| 1700 |
+
formset.errors,
|
| 1701 |
+
[{}, {"__all__": ["Please correct the duplicate values below."]}, {}],
|
| 1702 |
+
)
|
| 1703 |
+
|
| 1704 |
+
def test_model_formset_with_custom_pk(self):
|
| 1705 |
+
# a formset for a Model that has a custom primary key that still needs to be
|
| 1706 |
+
# added to the formset automatically
|
| 1707 |
+
FormSet = modelformset_factory(
|
| 1708 |
+
ClassyMexicanRestaurant, fields=["tacos_are_yummy"]
|
| 1709 |
+
)
|
| 1710 |
+
self.assertEqual(
|
| 1711 |
+
sorted(FormSet().forms[0].fields), ["tacos_are_yummy", "the_restaurant"]
|
| 1712 |
+
)
|
| 1713 |
+
|
| 1714 |
+
def test_model_formset_with_initial_model_instance(self):
|
| 1715 |
+
# has_changed should compare model instance and primary key
|
| 1716 |
+
# see #18898
|
| 1717 |
+
FormSet = modelformset_factory(Poem, fields="__all__")
|
| 1718 |
+
john_milton = Poet(name="John Milton")
|
| 1719 |
+
john_milton.save()
|
| 1720 |
+
data = {
|
| 1721 |
+
"form-TOTAL_FORMS": 1,
|
| 1722 |
+
"form-INITIAL_FORMS": 0,
|
| 1723 |
+
"form-MAX_NUM_FORMS": "",
|
| 1724 |
+
"form-0-name": "",
|
| 1725 |
+
"form-0-poet": str(john_milton.id),
|
| 1726 |
+
}
|
| 1727 |
+
formset = FormSet(initial=[{"poet": john_milton}], data=data)
|
| 1728 |
+
self.assertFalse(formset.extra_forms[0].has_changed())
|
| 1729 |
+
|
| 1730 |
+
def test_model_formset_with_initial_queryset(self):
|
| 1731 |
+
# has_changed should work with queryset and list of pk's
|
| 1732 |
+
# see #18898
|
| 1733 |
+
FormSet = modelformset_factory(AuthorMeeting, fields="__all__")
|
| 1734 |
+
Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 1735 |
+
data = {
|
| 1736 |
+
"form-TOTAL_FORMS": 1,
|
| 1737 |
+
"form-INITIAL_FORMS": 0,
|
| 1738 |
+
"form-MAX_NUM_FORMS": "",
|
| 1739 |
+
"form-0-name": "",
|
| 1740 |
+
"form-0-created": "",
|
| 1741 |
+
"form-0-authors": list(Author.objects.values_list("id", flat=True)),
|
| 1742 |
+
}
|
| 1743 |
+
formset = FormSet(initial=[{"authors": Author.objects.all()}], data=data)
|
| 1744 |
+
self.assertFalse(formset.extra_forms[0].has_changed())
|
| 1745 |
+
|
| 1746 |
+
def test_prevent_duplicates_from_with_the_same_formset(self):
|
| 1747 |
+
FormSet = modelformset_factory(Product, fields="__all__", extra=2)
|
| 1748 |
+
data = {
|
| 1749 |
+
"form-TOTAL_FORMS": 2,
|
| 1750 |
+
"form-INITIAL_FORMS": 0,
|
| 1751 |
+
"form-MAX_NUM_FORMS": "",
|
| 1752 |
+
"form-0-slug": "red_car",
|
| 1753 |
+
"form-1-slug": "red_car",
|
| 1754 |
+
}
|
| 1755 |
+
formset = FormSet(data)
|
| 1756 |
+
self.assertFalse(formset.is_valid())
|
| 1757 |
+
self.assertEqual(
|
| 1758 |
+
formset._non_form_errors, ["Please correct the duplicate data for slug."]
|
| 1759 |
+
)
|
| 1760 |
+
|
| 1761 |
+
FormSet = modelformset_factory(Price, fields="__all__", extra=2)
|
| 1762 |
+
data = {
|
| 1763 |
+
"form-TOTAL_FORMS": 2,
|
| 1764 |
+
"form-INITIAL_FORMS": 0,
|
| 1765 |
+
"form-MAX_NUM_FORMS": "",
|
| 1766 |
+
"form-0-price": "25",
|
| 1767 |
+
"form-0-quantity": "7",
|
| 1768 |
+
"form-1-price": "25",
|
| 1769 |
+
"form-1-quantity": "7",
|
| 1770 |
+
}
|
| 1771 |
+
formset = FormSet(data)
|
| 1772 |
+
self.assertFalse(formset.is_valid())
|
| 1773 |
+
self.assertEqual(
|
| 1774 |
+
formset._non_form_errors,
|
| 1775 |
+
[
|
| 1776 |
+
"Please correct the duplicate data for price and quantity, which must "
|
| 1777 |
+
"be unique."
|
| 1778 |
+
],
|
| 1779 |
+
)
|
| 1780 |
+
|
| 1781 |
+
# Only the price field is specified, this should skip any unique
|
| 1782 |
+
# checks since the unique_together is not fulfilled. This will fail
|
| 1783 |
+
# with a KeyError if broken.
|
| 1784 |
+
FormSet = modelformset_factory(Price, fields=("price",), extra=2)
|
| 1785 |
+
data = {
|
| 1786 |
+
"form-TOTAL_FORMS": "2",
|
| 1787 |
+
"form-INITIAL_FORMS": "0",
|
| 1788 |
+
"form-MAX_NUM_FORMS": "",
|
| 1789 |
+
"form-0-price": "24",
|
| 1790 |
+
"form-1-price": "24",
|
| 1791 |
+
}
|
| 1792 |
+
formset = FormSet(data)
|
| 1793 |
+
self.assertTrue(formset.is_valid())
|
| 1794 |
+
|
| 1795 |
+
FormSet = inlineformset_factory(Author, Book, extra=0, fields="__all__")
|
| 1796 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 1797 |
+
Book.objects.create(pk=1, author=author, title="Les Paradis Artificiels")
|
| 1798 |
+
Book.objects.create(pk=2, author=author, title="Les Fleurs du Mal")
|
| 1799 |
+
Book.objects.create(pk=3, author=author, title="Flowers of Evil")
|
| 1800 |
+
|
| 1801 |
+
book_ids = author.book_set.order_by("id").values_list("id", flat=True)
|
| 1802 |
+
data = {
|
| 1803 |
+
"book_set-TOTAL_FORMS": "2",
|
| 1804 |
+
"book_set-INITIAL_FORMS": "2",
|
| 1805 |
+
"book_set-MAX_NUM_FORMS": "",
|
| 1806 |
+
"book_set-0-title": "The 2008 Election",
|
| 1807 |
+
"book_set-0-author": str(author.id),
|
| 1808 |
+
"book_set-0-id": str(book_ids[0]),
|
| 1809 |
+
"book_set-1-title": "The 2008 Election",
|
| 1810 |
+
"book_set-1-author": str(author.id),
|
| 1811 |
+
"book_set-1-id": str(book_ids[1]),
|
| 1812 |
+
}
|
| 1813 |
+
formset = FormSet(data=data, instance=author)
|
| 1814 |
+
self.assertFalse(formset.is_valid())
|
| 1815 |
+
self.assertEqual(
|
| 1816 |
+
formset._non_form_errors, ["Please correct the duplicate data for title."]
|
| 1817 |
+
)
|
| 1818 |
+
self.assertEqual(
|
| 1819 |
+
formset.errors,
|
| 1820 |
+
[{}, {"__all__": ["Please correct the duplicate values below."]}],
|
| 1821 |
+
)
|
| 1822 |
+
|
| 1823 |
+
FormSet = modelformset_factory(Post, fields="__all__", extra=2)
|
| 1824 |
+
data = {
|
| 1825 |
+
"form-TOTAL_FORMS": "2",
|
| 1826 |
+
"form-INITIAL_FORMS": "0",
|
| 1827 |
+
"form-MAX_NUM_FORMS": "",
|
| 1828 |
+
"form-0-title": "blah",
|
| 1829 |
+
"form-0-slug": "Morning",
|
| 1830 |
+
"form-0-subtitle": "foo",
|
| 1831 |
+
"form-0-posted": "2009-01-01",
|
| 1832 |
+
"form-1-title": "blah",
|
| 1833 |
+
"form-1-slug": "Morning in Prague",
|
| 1834 |
+
"form-1-subtitle": "rawr",
|
| 1835 |
+
"form-1-posted": "2009-01-01",
|
| 1836 |
+
}
|
| 1837 |
+
formset = FormSet(data)
|
| 1838 |
+
self.assertFalse(formset.is_valid())
|
| 1839 |
+
self.assertEqual(
|
| 1840 |
+
formset._non_form_errors,
|
| 1841 |
+
[
|
| 1842 |
+
"Please correct the duplicate data for title which must be unique for "
|
| 1843 |
+
"the date in posted."
|
| 1844 |
+
],
|
| 1845 |
+
)
|
| 1846 |
+
self.assertEqual(
|
| 1847 |
+
formset.errors,
|
| 1848 |
+
[{}, {"__all__": ["Please correct the duplicate values below."]}],
|
| 1849 |
+
)
|
| 1850 |
+
|
| 1851 |
+
data = {
|
| 1852 |
+
"form-TOTAL_FORMS": "2",
|
| 1853 |
+
"form-INITIAL_FORMS": "0",
|
| 1854 |
+
"form-MAX_NUM_FORMS": "",
|
| 1855 |
+
"form-0-title": "foo",
|
| 1856 |
+
"form-0-slug": "Morning in Prague",
|
| 1857 |
+
"form-0-subtitle": "foo",
|
| 1858 |
+
"form-0-posted": "2009-01-01",
|
| 1859 |
+
"form-1-title": "blah",
|
| 1860 |
+
"form-1-slug": "Morning in Prague",
|
| 1861 |
+
"form-1-subtitle": "rawr",
|
| 1862 |
+
"form-1-posted": "2009-08-02",
|
| 1863 |
+
}
|
| 1864 |
+
formset = FormSet(data)
|
| 1865 |
+
self.assertFalse(formset.is_valid())
|
| 1866 |
+
self.assertEqual(
|
| 1867 |
+
formset._non_form_errors,
|
| 1868 |
+
[
|
| 1869 |
+
"Please correct the duplicate data for slug which must be unique for "
|
| 1870 |
+
"the year in posted."
|
| 1871 |
+
],
|
| 1872 |
+
)
|
| 1873 |
+
|
| 1874 |
+
data = {
|
| 1875 |
+
"form-TOTAL_FORMS": "2",
|
| 1876 |
+
"form-INITIAL_FORMS": "0",
|
| 1877 |
+
"form-MAX_NUM_FORMS": "",
|
| 1878 |
+
"form-0-title": "foo",
|
| 1879 |
+
"form-0-slug": "Morning in Prague",
|
| 1880 |
+
"form-0-subtitle": "rawr",
|
| 1881 |
+
"form-0-posted": "2008-08-01",
|
| 1882 |
+
"form-1-title": "blah",
|
| 1883 |
+
"form-1-slug": "Prague",
|
| 1884 |
+
"form-1-subtitle": "rawr",
|
| 1885 |
+
"form-1-posted": "2009-08-02",
|
| 1886 |
+
}
|
| 1887 |
+
formset = FormSet(data)
|
| 1888 |
+
self.assertFalse(formset.is_valid())
|
| 1889 |
+
self.assertEqual(
|
| 1890 |
+
formset._non_form_errors,
|
| 1891 |
+
[
|
| 1892 |
+
"Please correct the duplicate data for subtitle which must be unique "
|
| 1893 |
+
"for the month in posted."
|
| 1894 |
+
],
|
| 1895 |
+
)
|
| 1896 |
+
|
| 1897 |
+
def test_prevent_change_outer_model_and_create_invalid_data(self):
|
| 1898 |
+
author = Author.objects.create(name="Charles")
|
| 1899 |
+
other_author = Author.objects.create(name="Walt")
|
| 1900 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__")
|
| 1901 |
+
data = {
|
| 1902 |
+
"form-TOTAL_FORMS": "2",
|
| 1903 |
+
"form-INITIAL_FORMS": "2",
|
| 1904 |
+
"form-MAX_NUM_FORMS": "",
|
| 1905 |
+
"form-0-id": str(author.id),
|
| 1906 |
+
"form-0-name": "Charles",
|
| 1907 |
+
"form-1-id": str(other_author.id), # A model not in the formset's queryset.
|
| 1908 |
+
"form-1-name": "Changed name",
|
| 1909 |
+
}
|
| 1910 |
+
# This formset is only for Walt Whitman and shouldn't accept data for
|
| 1911 |
+
# other_author.
|
| 1912 |
+
formset = AuthorFormSet(
|
| 1913 |
+
data=data, queryset=Author.objects.filter(id__in=(author.id,))
|
| 1914 |
+
)
|
| 1915 |
+
self.assertTrue(formset.is_valid())
|
| 1916 |
+
formset.save()
|
| 1917 |
+
# The name of other_author shouldn't be changed and new models aren't
|
| 1918 |
+
# created.
|
| 1919 |
+
self.assertSequenceEqual(Author.objects.all(), [author, other_author])
|
| 1920 |
+
|
| 1921 |
+
def test_validation_without_id(self):
|
| 1922 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__")
|
| 1923 |
+
data = {
|
| 1924 |
+
"form-TOTAL_FORMS": "1",
|
| 1925 |
+
"form-INITIAL_FORMS": "1",
|
| 1926 |
+
"form-MAX_NUM_FORMS": "",
|
| 1927 |
+
"form-0-name": "Charles",
|
| 1928 |
+
}
|
| 1929 |
+
formset = AuthorFormSet(data)
|
| 1930 |
+
self.assertEqual(
|
| 1931 |
+
formset.errors,
|
| 1932 |
+
[{"id": ["This field is required."]}],
|
| 1933 |
+
)
|
| 1934 |
+
|
| 1935 |
+
def test_validation_with_child_model_without_id(self):
|
| 1936 |
+
BetterAuthorFormSet = modelformset_factory(BetterAuthor, fields="__all__")
|
| 1937 |
+
data = {
|
| 1938 |
+
"form-TOTAL_FORMS": "1",
|
| 1939 |
+
"form-INITIAL_FORMS": "1",
|
| 1940 |
+
"form-MAX_NUM_FORMS": "",
|
| 1941 |
+
"form-0-name": "Charles",
|
| 1942 |
+
"form-0-write_speed": "10",
|
| 1943 |
+
}
|
| 1944 |
+
formset = BetterAuthorFormSet(data)
|
| 1945 |
+
self.assertEqual(
|
| 1946 |
+
formset.errors,
|
| 1947 |
+
[{"author_ptr": ["This field is required."]}],
|
| 1948 |
+
)
|
| 1949 |
+
|
| 1950 |
+
def test_validation_with_invalid_id(self):
|
| 1951 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__")
|
| 1952 |
+
data = {
|
| 1953 |
+
"form-TOTAL_FORMS": "1",
|
| 1954 |
+
"form-INITIAL_FORMS": "1",
|
| 1955 |
+
"form-MAX_NUM_FORMS": "",
|
| 1956 |
+
"form-0-id": "abc",
|
| 1957 |
+
"form-0-name": "Charles",
|
| 1958 |
+
}
|
| 1959 |
+
formset = AuthorFormSet(data)
|
| 1960 |
+
self.assertEqual(
|
| 1961 |
+
formset.errors,
|
| 1962 |
+
[
|
| 1963 |
+
{
|
| 1964 |
+
"id": [
|
| 1965 |
+
"Select a valid choice. That choice is not one of the "
|
| 1966 |
+
"available choices."
|
| 1967 |
+
]
|
| 1968 |
+
}
|
| 1969 |
+
],
|
| 1970 |
+
)
|
| 1971 |
+
|
| 1972 |
+
def test_validation_with_nonexistent_id(self):
|
| 1973 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__")
|
| 1974 |
+
data = {
|
| 1975 |
+
"form-TOTAL_FORMS": "1",
|
| 1976 |
+
"form-INITIAL_FORMS": "1",
|
| 1977 |
+
"form-MAX_NUM_FORMS": "",
|
| 1978 |
+
"form-0-id": "12345",
|
| 1979 |
+
"form-0-name": "Charles",
|
| 1980 |
+
}
|
| 1981 |
+
formset = AuthorFormSet(data)
|
| 1982 |
+
self.assertEqual(
|
| 1983 |
+
formset.errors,
|
| 1984 |
+
[
|
| 1985 |
+
{
|
| 1986 |
+
"id": [
|
| 1987 |
+
"Select a valid choice. That choice is not one of the "
|
| 1988 |
+
"available choices."
|
| 1989 |
+
]
|
| 1990 |
+
}
|
| 1991 |
+
],
|
| 1992 |
+
)
|
| 1993 |
+
|
| 1994 |
+
def test_initial_form_count_empty_data(self):
|
| 1995 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__")
|
| 1996 |
+
formset = AuthorFormSet({})
|
| 1997 |
+
self.assertEqual(formset.initial_form_count(), 0)
|
| 1998 |
+
|
| 1999 |
+
def test_edit_only(self):
|
| 2000 |
+
charles = Author.objects.create(name="Charles Baudelaire")
|
| 2001 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", edit_only=True)
|
| 2002 |
+
data = {
|
| 2003 |
+
"form-TOTAL_FORMS": "2",
|
| 2004 |
+
"form-INITIAL_FORMS": "0",
|
| 2005 |
+
"form-MAX_NUM_FORMS": "0",
|
| 2006 |
+
"form-0-name": "Arthur Rimbaud",
|
| 2007 |
+
"form-1-name": "Walt Whitman",
|
| 2008 |
+
}
|
| 2009 |
+
formset = AuthorFormSet(data)
|
| 2010 |
+
self.assertIs(formset.is_valid(), True)
|
| 2011 |
+
formset.save()
|
| 2012 |
+
self.assertSequenceEqual(Author.objects.all(), [charles])
|
| 2013 |
+
data = {
|
| 2014 |
+
"form-TOTAL_FORMS": "2",
|
| 2015 |
+
"form-INITIAL_FORMS": "1",
|
| 2016 |
+
"form-MAX_NUM_FORMS": "0",
|
| 2017 |
+
"form-0-id": charles.pk,
|
| 2018 |
+
"form-0-name": "Arthur Rimbaud",
|
| 2019 |
+
"form-1-name": "Walt Whitman",
|
| 2020 |
+
}
|
| 2021 |
+
formset = AuthorFormSet(data)
|
| 2022 |
+
self.assertIs(formset.is_valid(), True)
|
| 2023 |
+
formset.save()
|
| 2024 |
+
charles.refresh_from_db()
|
| 2025 |
+
self.assertEqual(charles.name, "Arthur Rimbaud")
|
| 2026 |
+
self.assertSequenceEqual(Author.objects.all(), [charles])
|
| 2027 |
+
|
| 2028 |
+
def test_edit_only_inlineformset_factory(self):
|
| 2029 |
+
charles = Author.objects.create(name="Charles Baudelaire")
|
| 2030 |
+
book = Book.objects.create(author=charles, title="Les Paradis Artificiels")
|
| 2031 |
+
AuthorFormSet = inlineformset_factory(
|
| 2032 |
+
Author,
|
| 2033 |
+
Book,
|
| 2034 |
+
can_delete=False,
|
| 2035 |
+
fields="__all__",
|
| 2036 |
+
edit_only=True,
|
| 2037 |
+
)
|
| 2038 |
+
data = {
|
| 2039 |
+
"book_set-TOTAL_FORMS": "4",
|
| 2040 |
+
"book_set-INITIAL_FORMS": "1",
|
| 2041 |
+
"book_set-MAX_NUM_FORMS": "0",
|
| 2042 |
+
"book_set-0-id": book.pk,
|
| 2043 |
+
"book_set-0-title": "Les Fleurs du Mal",
|
| 2044 |
+
"book_set-0-author": charles.pk,
|
| 2045 |
+
"book_set-1-title": "Flowers of Evil",
|
| 2046 |
+
"book_set-1-author": charles.pk,
|
| 2047 |
+
}
|
| 2048 |
+
formset = AuthorFormSet(data, instance=charles)
|
| 2049 |
+
self.assertIs(formset.is_valid(), True)
|
| 2050 |
+
formset.save()
|
| 2051 |
+
book.refresh_from_db()
|
| 2052 |
+
self.assertEqual(book.title, "Les Fleurs du Mal")
|
| 2053 |
+
self.assertSequenceEqual(Book.objects.all(), [book])
|
| 2054 |
+
|
| 2055 |
+
def test_edit_only_object_outside_of_queryset(self):
|
| 2056 |
+
charles = Author.objects.create(name="Charles Baudelaire")
|
| 2057 |
+
walt = Author.objects.create(name="Walt Whitman")
|
| 2058 |
+
data = {
|
| 2059 |
+
"form-TOTAL_FORMS": "1",
|
| 2060 |
+
"form-INITIAL_FORMS": "1",
|
| 2061 |
+
"form-0-id": walt.pk,
|
| 2062 |
+
"form-0-name": "Parth Patil",
|
| 2063 |
+
}
|
| 2064 |
+
AuthorFormSet = modelformset_factory(Author, fields="__all__", edit_only=True)
|
| 2065 |
+
formset = AuthorFormSet(data, queryset=Author.objects.filter(pk=charles.pk))
|
| 2066 |
+
self.assertIs(formset.is_valid(), True)
|
| 2067 |
+
formset.save()
|
| 2068 |
+
self.assertCountEqual(Author.objects.all(), [charles, walt])
|
| 2069 |
+
|
| 2070 |
+
def test_edit_only_formset_factory_with_basemodelformset(self):
|
| 2071 |
+
charles = Author.objects.create(name="Charles Baudelaire")
|
| 2072 |
+
|
| 2073 |
+
class AuthorForm(forms.ModelForm):
|
| 2074 |
+
class Meta:
|
| 2075 |
+
model = Author
|
| 2076 |
+
fields = "__all__"
|
| 2077 |
+
|
| 2078 |
+
class BaseAuthorFormSet(BaseModelFormSet):
|
| 2079 |
+
def __init__(self, *args, **kwargs):
|
| 2080 |
+
self.model = Author
|
| 2081 |
+
super().__init__(*args, **kwargs)
|
| 2082 |
+
|
| 2083 |
+
AuthorFormSet = formset_factory(AuthorForm, formset=BaseAuthorFormSet)
|
| 2084 |
+
data = {
|
| 2085 |
+
"form-TOTAL_FORMS": "2",
|
| 2086 |
+
"form-INITIAL_FORMS": "1",
|
| 2087 |
+
"form-MAX_NUM_FORMS": "0",
|
| 2088 |
+
"form-0-id": charles.pk,
|
| 2089 |
+
"form-0-name": "Shawn Dong",
|
| 2090 |
+
"form-1-name": "Walt Whitman",
|
| 2091 |
+
}
|
| 2092 |
+
formset = AuthorFormSet(data)
|
| 2093 |
+
self.assertIs(formset.is_valid(), True)
|
| 2094 |
+
formset.save()
|
| 2095 |
+
self.assertEqual(Author.objects.count(), 2)
|
| 2096 |
+
charles.refresh_from_db()
|
| 2097 |
+
self.assertEqual(charles.name, "Shawn Dong")
|
| 2098 |
+
self.assertEqual(Author.objects.count(), 2)
|
| 2099 |
+
|
| 2100 |
+
|
| 2101 |
+
class TestModelFormsetOverridesTroughFormMeta(TestCase):
|
| 2102 |
+
def test_modelformset_factory_widgets(self):
|
| 2103 |
+
widgets = {"name": forms.TextInput(attrs={"class": "poet"})}
|
| 2104 |
+
PoetFormSet = modelformset_factory(Poet, fields="__all__", widgets=widgets)
|
| 2105 |
+
form = PoetFormSet.form()
|
| 2106 |
+
self.assertHTMLEqual(
|
| 2107 |
+
str(form["name"]),
|
| 2108 |
+
'<input id="id_name" maxlength="100" type="text" class="poet" name="name" '
|
| 2109 |
+
"required>",
|
| 2110 |
+
)
|
| 2111 |
+
|
| 2112 |
+
def test_inlineformset_factory_widgets(self):
|
| 2113 |
+
widgets = {"title": forms.TextInput(attrs={"class": "book"})}
|
| 2114 |
+
BookFormSet = inlineformset_factory(
|
| 2115 |
+
Author, Book, widgets=widgets, fields="__all__"
|
| 2116 |
+
)
|
| 2117 |
+
form = BookFormSet.form()
|
| 2118 |
+
self.assertHTMLEqual(
|
| 2119 |
+
str(form["title"]),
|
| 2120 |
+
'<input class="book" id="id_title" maxlength="100" name="title" '
|
| 2121 |
+
'type="text" required>',
|
| 2122 |
+
)
|
| 2123 |
+
|
| 2124 |
+
def test_modelformset_factory_labels_overrides(self):
|
| 2125 |
+
BookFormSet = modelformset_factory(
|
| 2126 |
+
Book, fields="__all__", labels={"title": "Name"}
|
| 2127 |
+
)
|
| 2128 |
+
form = BookFormSet.form()
|
| 2129 |
+
self.assertHTMLEqual(
|
| 2130 |
+
form["title"].label_tag(), '<label for="id_title">Name:</label>'
|
| 2131 |
+
)
|
| 2132 |
+
self.assertHTMLEqual(
|
| 2133 |
+
form["title"].legend_tag(),
|
| 2134 |
+
'<legend for="id_title">Name:</legend>',
|
| 2135 |
+
)
|
| 2136 |
+
|
| 2137 |
+
def test_inlineformset_factory_labels_overrides(self):
|
| 2138 |
+
BookFormSet = inlineformset_factory(
|
| 2139 |
+
Author, Book, fields="__all__", labels={"title": "Name"}
|
| 2140 |
+
)
|
| 2141 |
+
form = BookFormSet.form()
|
| 2142 |
+
self.assertHTMLEqual(
|
| 2143 |
+
form["title"].label_tag(), '<label for="id_title">Name:</label>'
|
| 2144 |
+
)
|
| 2145 |
+
self.assertHTMLEqual(
|
| 2146 |
+
form["title"].legend_tag(),
|
| 2147 |
+
'<legend for="id_title">Name:</legend>',
|
| 2148 |
+
)
|
| 2149 |
+
|
| 2150 |
+
def test_modelformset_factory_help_text_overrides(self):
|
| 2151 |
+
BookFormSet = modelformset_factory(
|
| 2152 |
+
Book, fields="__all__", help_texts={"title": "Choose carefully."}
|
| 2153 |
+
)
|
| 2154 |
+
form = BookFormSet.form()
|
| 2155 |
+
self.assertEqual(form["title"].help_text, "Choose carefully.")
|
| 2156 |
+
|
| 2157 |
+
def test_inlineformset_factory_help_text_overrides(self):
|
| 2158 |
+
BookFormSet = inlineformset_factory(
|
| 2159 |
+
Author, Book, fields="__all__", help_texts={"title": "Choose carefully."}
|
| 2160 |
+
)
|
| 2161 |
+
form = BookFormSet.form()
|
| 2162 |
+
self.assertEqual(form["title"].help_text, "Choose carefully.")
|
| 2163 |
+
|
| 2164 |
+
def test_modelformset_factory_error_messages_overrides(self):
|
| 2165 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 2166 |
+
BookFormSet = modelformset_factory(
|
| 2167 |
+
Book,
|
| 2168 |
+
fields="__all__",
|
| 2169 |
+
error_messages={"title": {"max_length": "Title too long!!"}},
|
| 2170 |
+
)
|
| 2171 |
+
form = BookFormSet.form(data={"title": "Foo " * 30, "author": author.id})
|
| 2172 |
+
form.full_clean()
|
| 2173 |
+
self.assertEqual(form.errors, {"title": ["Title too long!!"]})
|
| 2174 |
+
|
| 2175 |
+
def test_inlineformset_factory_error_messages_overrides(self):
|
| 2176 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 2177 |
+
BookFormSet = inlineformset_factory(
|
| 2178 |
+
Author,
|
| 2179 |
+
Book,
|
| 2180 |
+
fields="__all__",
|
| 2181 |
+
error_messages={"title": {"max_length": "Title too long!!"}},
|
| 2182 |
+
)
|
| 2183 |
+
form = BookFormSet.form(data={"title": "Foo " * 30, "author": author.id})
|
| 2184 |
+
form.full_clean()
|
| 2185 |
+
self.assertEqual(form.errors, {"title": ["Title too long!!"]})
|
| 2186 |
+
|
| 2187 |
+
def test_modelformset_factory_field_class_overrides(self):
|
| 2188 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 2189 |
+
BookFormSet = modelformset_factory(
|
| 2190 |
+
Book,
|
| 2191 |
+
fields="__all__",
|
| 2192 |
+
field_classes={
|
| 2193 |
+
"title": forms.SlugField,
|
| 2194 |
+
},
|
| 2195 |
+
)
|
| 2196 |
+
form = BookFormSet.form(data={"title": "Foo " * 30, "author": author.id})
|
| 2197 |
+
self.assertIs(Book._meta.get_field("title").__class__, models.CharField)
|
| 2198 |
+
self.assertIsInstance(form.fields["title"], forms.SlugField)
|
| 2199 |
+
|
| 2200 |
+
def test_inlineformset_factory_field_class_overrides(self):
|
| 2201 |
+
author = Author.objects.create(pk=1, name="Charles Baudelaire")
|
| 2202 |
+
BookFormSet = inlineformset_factory(
|
| 2203 |
+
Author,
|
| 2204 |
+
Book,
|
| 2205 |
+
fields="__all__",
|
| 2206 |
+
field_classes={
|
| 2207 |
+
"title": forms.SlugField,
|
| 2208 |
+
},
|
| 2209 |
+
)
|
| 2210 |
+
form = BookFormSet.form(data={"title": "Foo " * 30, "author": author.id})
|
| 2211 |
+
self.assertIs(Book._meta.get_field("title").__class__, models.CharField)
|
| 2212 |
+
self.assertIsInstance(form.fields["title"], forms.SlugField)
|
| 2213 |
+
|
| 2214 |
+
def test_modelformset_factory_absolute_max(self):
|
| 2215 |
+
AuthorFormSet = modelformset_factory(
|
| 2216 |
+
Author, fields="__all__", absolute_max=1500
|
| 2217 |
+
)
|
| 2218 |
+
data = {
|
| 2219 |
+
"form-TOTAL_FORMS": "1501",
|
| 2220 |
+
"form-INITIAL_FORMS": "0",
|
| 2221 |
+
"form-MAX_NUM_FORMS": "0",
|
| 2222 |
+
}
|
| 2223 |
+
formset = AuthorFormSet(data=data)
|
| 2224 |
+
self.assertIs(formset.is_valid(), False)
|
| 2225 |
+
self.assertEqual(len(formset.forms), 1500)
|
| 2226 |
+
self.assertEqual(
|
| 2227 |
+
formset.non_form_errors(),
|
| 2228 |
+
["Please submit at most 1000 forms."],
|
| 2229 |
+
)
|
| 2230 |
+
|
| 2231 |
+
def test_modelformset_factory_absolute_max_with_max_num(self):
|
| 2232 |
+
AuthorFormSet = modelformset_factory(
|
| 2233 |
+
Author,
|
| 2234 |
+
fields="__all__",
|
| 2235 |
+
max_num=20,
|
| 2236 |
+
absolute_max=100,
|
| 2237 |
+
)
|
| 2238 |
+
data = {
|
| 2239 |
+
"form-TOTAL_FORMS": "101",
|
| 2240 |
+
"form-INITIAL_FORMS": "0",
|
| 2241 |
+
"form-MAX_NUM_FORMS": "0",
|
| 2242 |
+
}
|
| 2243 |
+
formset = AuthorFormSet(data=data)
|
| 2244 |
+
self.assertIs(formset.is_valid(), False)
|
| 2245 |
+
self.assertEqual(len(formset.forms), 100)
|
| 2246 |
+
self.assertEqual(
|
| 2247 |
+
formset.non_form_errors(),
|
| 2248 |
+
["Please submit at most 20 forms."],
|
| 2249 |
+
)
|
| 2250 |
+
|
| 2251 |
+
def test_inlineformset_factory_absolute_max(self):
|
| 2252 |
+
author = Author.objects.create(name="Charles Baudelaire")
|
| 2253 |
+
BookFormSet = inlineformset_factory(
|
| 2254 |
+
Author,
|
| 2255 |
+
Book,
|
| 2256 |
+
fields="__all__",
|
| 2257 |
+
absolute_max=1500,
|
| 2258 |
+
)
|
| 2259 |
+
data = {
|
| 2260 |
+
"book_set-TOTAL_FORMS": "1501",
|
| 2261 |
+
"book_set-INITIAL_FORMS": "0",
|
| 2262 |
+
"book_set-MAX_NUM_FORMS": "0",
|
| 2263 |
+
}
|
| 2264 |
+
formset = BookFormSet(data, instance=author)
|
| 2265 |
+
self.assertIs(formset.is_valid(), False)
|
| 2266 |
+
self.assertEqual(len(formset.forms), 1500)
|
| 2267 |
+
self.assertEqual(
|
| 2268 |
+
formset.non_form_errors(),
|
| 2269 |
+
["Please submit at most 1000 forms."],
|
| 2270 |
+
)
|
| 2271 |
+
|
| 2272 |
+
def test_inlineformset_factory_absolute_max_with_max_num(self):
|
| 2273 |
+
author = Author.objects.create(name="Charles Baudelaire")
|
| 2274 |
+
BookFormSet = inlineformset_factory(
|
| 2275 |
+
Author,
|
| 2276 |
+
Book,
|
| 2277 |
+
fields="__all__",
|
| 2278 |
+
max_num=20,
|
| 2279 |
+
absolute_max=100,
|
| 2280 |
+
)
|
| 2281 |
+
data = {
|
| 2282 |
+
"book_set-TOTAL_FORMS": "101",
|
| 2283 |
+
"book_set-INITIAL_FORMS": "0",
|
| 2284 |
+
"book_set-MAX_NUM_FORMS": "0",
|
| 2285 |
+
}
|
| 2286 |
+
formset = BookFormSet(data, instance=author)
|
| 2287 |
+
self.assertIs(formset.is_valid(), False)
|
| 2288 |
+
self.assertEqual(len(formset.forms), 100)
|
| 2289 |
+
self.assertEqual(
|
| 2290 |
+
formset.non_form_errors(),
|
| 2291 |
+
["Please submit at most 20 forms."],
|
| 2292 |
+
)
|
| 2293 |
+
|
| 2294 |
+
def test_modelformset_factory_can_delete_extra(self):
|
| 2295 |
+
AuthorFormSet = modelformset_factory(
|
| 2296 |
+
Author,
|
| 2297 |
+
fields="__all__",
|
| 2298 |
+
can_delete=True,
|
| 2299 |
+
can_delete_extra=True,
|
| 2300 |
+
extra=2,
|
| 2301 |
+
)
|
| 2302 |
+
formset = AuthorFormSet()
|
| 2303 |
+
self.assertEqual(len(formset), 2)
|
| 2304 |
+
self.assertIn("DELETE", formset.forms[0].fields)
|
| 2305 |
+
self.assertIn("DELETE", formset.forms[1].fields)
|
| 2306 |
+
|
| 2307 |
+
def test_modelformset_factory_disable_delete_extra(self):
|
| 2308 |
+
AuthorFormSet = modelformset_factory(
|
| 2309 |
+
Author,
|
| 2310 |
+
fields="__all__",
|
| 2311 |
+
can_delete=True,
|
| 2312 |
+
can_delete_extra=False,
|
| 2313 |
+
extra=2,
|
| 2314 |
+
)
|
| 2315 |
+
formset = AuthorFormSet()
|
| 2316 |
+
self.assertEqual(len(formset), 2)
|
| 2317 |
+
self.assertNotIn("DELETE", formset.forms[0].fields)
|
| 2318 |
+
self.assertNotIn("DELETE", formset.forms[1].fields)
|
| 2319 |
+
|
| 2320 |
+
def test_inlineformset_factory_can_delete_extra(self):
|
| 2321 |
+
BookFormSet = inlineformset_factory(
|
| 2322 |
+
Author,
|
| 2323 |
+
Book,
|
| 2324 |
+
fields="__all__",
|
| 2325 |
+
can_delete=True,
|
| 2326 |
+
can_delete_extra=True,
|
| 2327 |
+
extra=2,
|
| 2328 |
+
)
|
| 2329 |
+
formset = BookFormSet()
|
| 2330 |
+
self.assertEqual(len(formset), 2)
|
| 2331 |
+
self.assertIn("DELETE", formset.forms[0].fields)
|
| 2332 |
+
self.assertIn("DELETE", formset.forms[1].fields)
|
| 2333 |
+
|
| 2334 |
+
def test_inlineformset_factory_can_not_delete_extra(self):
|
| 2335 |
+
BookFormSet = inlineformset_factory(
|
| 2336 |
+
Author,
|
| 2337 |
+
Book,
|
| 2338 |
+
fields="__all__",
|
| 2339 |
+
can_delete=True,
|
| 2340 |
+
can_delete_extra=False,
|
| 2341 |
+
extra=2,
|
| 2342 |
+
)
|
| 2343 |
+
formset = BookFormSet()
|
| 2344 |
+
self.assertEqual(len(formset), 2)
|
| 2345 |
+
self.assertNotIn("DELETE", formset.forms[0].fields)
|
| 2346 |
+
self.assertNotIn("DELETE", formset.forms[1].fields)
|
| 2347 |
+
|
| 2348 |
+
def test_inlineformset_factory_passes_renderer(self):
|
| 2349 |
+
from django.forms.renderers import Jinja2
|
| 2350 |
+
|
| 2351 |
+
renderer = Jinja2()
|
| 2352 |
+
BookFormSet = inlineformset_factory(
|
| 2353 |
+
Author,
|
| 2354 |
+
Book,
|
| 2355 |
+
fields="__all__",
|
| 2356 |
+
renderer=renderer,
|
| 2357 |
+
)
|
| 2358 |
+
formset = BookFormSet()
|
| 2359 |
+
self.assertEqual(formset.renderer, renderer)
|
| 2360 |
+
|
| 2361 |
+
def test_modelformset_factory_passes_renderer(self):
|
| 2362 |
+
from django.forms.renderers import Jinja2
|
| 2363 |
+
|
| 2364 |
+
renderer = Jinja2()
|
| 2365 |
+
BookFormSet = modelformset_factory(Author, fields="__all__", renderer=renderer)
|
| 2366 |
+
formset = BookFormSet()
|
| 2367 |
+
self.assertEqual(formset.renderer, renderer)
|
testbed/django__django/tests/model_formsets_regress/__init__.py
ADDED
|
File without changes
|
testbed/django__django/tests/model_formsets_regress/tests.py
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
modelform_factory,
|
| 7 |
+
modelformset_factory,
|
| 8 |
+
)
|
| 9 |
+
from django.forms.utils import ErrorDict, ErrorList
|
| 10 |
+
from django.test import TestCase
|
| 11 |
+
|
| 12 |
+
from .models import (
|
| 13 |
+
Host,
|
| 14 |
+
Manager,
|
| 15 |
+
Network,
|
| 16 |
+
ProfileNetwork,
|
| 17 |
+
Restaurant,
|
| 18 |
+
User,
|
| 19 |
+
UserPreferences,
|
| 20 |
+
UserProfile,
|
| 21 |
+
UserSite,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class InlineFormsetTests(TestCase):
|
| 26 |
+
def test_formset_over_to_field(self):
|
| 27 |
+
"""
|
| 28 |
+
A formset over a ForeignKey with a to_field can be saved.
|
| 29 |
+
"""
|
| 30 |
+
Form = modelform_factory(User, fields="__all__")
|
| 31 |
+
FormSet = inlineformset_factory(User, UserSite, fields="__all__")
|
| 32 |
+
|
| 33 |
+
# Instantiate the Form and FormSet to prove
|
| 34 |
+
# you can create a form with no data
|
| 35 |
+
form = Form()
|
| 36 |
+
form_set = FormSet(instance=User())
|
| 37 |
+
|
| 38 |
+
# Now create a new User and UserSite instance
|
| 39 |
+
data = {
|
| 40 |
+
"serial": "1",
|
| 41 |
+
"username": "apollo13",
|
| 42 |
+
"usersite_set-TOTAL_FORMS": "1",
|
| 43 |
+
"usersite_set-INITIAL_FORMS": "0",
|
| 44 |
+
"usersite_set-MAX_NUM_FORMS": "0",
|
| 45 |
+
"usersite_set-0-data": "10",
|
| 46 |
+
"usersite_set-0-user": "apollo13",
|
| 47 |
+
}
|
| 48 |
+
user = User()
|
| 49 |
+
form = Form(data)
|
| 50 |
+
if form.is_valid():
|
| 51 |
+
user = form.save()
|
| 52 |
+
else:
|
| 53 |
+
self.fail("Errors found on form:%s" % form_set)
|
| 54 |
+
|
| 55 |
+
form_set = FormSet(data, instance=user)
|
| 56 |
+
if form_set.is_valid():
|
| 57 |
+
form_set.save()
|
| 58 |
+
usersite = UserSite.objects.values()
|
| 59 |
+
self.assertEqual(usersite[0]["data"], 10)
|
| 60 |
+
self.assertEqual(usersite[0]["user_id"], "apollo13")
|
| 61 |
+
else:
|
| 62 |
+
self.fail("Errors found on formset:%s" % form_set.errors)
|
| 63 |
+
|
| 64 |
+
# Now update the UserSite instance
|
| 65 |
+
data = {
|
| 66 |
+
"usersite_set-TOTAL_FORMS": "1",
|
| 67 |
+
"usersite_set-INITIAL_FORMS": "1",
|
| 68 |
+
"usersite_set-MAX_NUM_FORMS": "0",
|
| 69 |
+
"usersite_set-0-id": str(usersite[0]["id"]),
|
| 70 |
+
"usersite_set-0-data": "11",
|
| 71 |
+
"usersite_set-0-user": "apollo13",
|
| 72 |
+
}
|
| 73 |
+
form_set = FormSet(data, instance=user)
|
| 74 |
+
if form_set.is_valid():
|
| 75 |
+
form_set.save()
|
| 76 |
+
usersite = UserSite.objects.values()
|
| 77 |
+
self.assertEqual(usersite[0]["data"], 11)
|
| 78 |
+
self.assertEqual(usersite[0]["user_id"], "apollo13")
|
| 79 |
+
else:
|
| 80 |
+
self.fail("Errors found on formset:%s" % form_set.errors)
|
| 81 |
+
|
| 82 |
+
# Now add a new UserSite instance
|
| 83 |
+
data = {
|
| 84 |
+
"usersite_set-TOTAL_FORMS": "2",
|
| 85 |
+
"usersite_set-INITIAL_FORMS": "1",
|
| 86 |
+
"usersite_set-MAX_NUM_FORMS": "0",
|
| 87 |
+
"usersite_set-0-id": str(usersite[0]["id"]),
|
| 88 |
+
"usersite_set-0-data": "11",
|
| 89 |
+
"usersite_set-0-user": "apollo13",
|
| 90 |
+
"usersite_set-1-data": "42",
|
| 91 |
+
"usersite_set-1-user": "apollo13",
|
| 92 |
+
}
|
| 93 |
+
form_set = FormSet(data, instance=user)
|
| 94 |
+
if form_set.is_valid():
|
| 95 |
+
form_set.save()
|
| 96 |
+
usersite = UserSite.objects.values().order_by("data")
|
| 97 |
+
self.assertEqual(usersite[0]["data"], 11)
|
| 98 |
+
self.assertEqual(usersite[0]["user_id"], "apollo13")
|
| 99 |
+
self.assertEqual(usersite[1]["data"], 42)
|
| 100 |
+
self.assertEqual(usersite[1]["user_id"], "apollo13")
|
| 101 |
+
else:
|
| 102 |
+
self.fail("Errors found on formset:%s" % form_set.errors)
|
| 103 |
+
|
| 104 |
+
def test_formset_over_inherited_model(self):
|
| 105 |
+
"""
|
| 106 |
+
A formset over a ForeignKey with a to_field can be saved.
|
| 107 |
+
"""
|
| 108 |
+
Form = modelform_factory(Restaurant, fields="__all__")
|
| 109 |
+
FormSet = inlineformset_factory(Restaurant, Manager, fields="__all__")
|
| 110 |
+
|
| 111 |
+
# Instantiate the Form and FormSet to prove
|
| 112 |
+
# you can create a form with no data
|
| 113 |
+
form = Form()
|
| 114 |
+
form_set = FormSet(instance=Restaurant())
|
| 115 |
+
|
| 116 |
+
# Now create a new Restaurant and Manager instance
|
| 117 |
+
data = {
|
| 118 |
+
"name": "Guido's House of Pasta",
|
| 119 |
+
"manager_set-TOTAL_FORMS": "1",
|
| 120 |
+
"manager_set-INITIAL_FORMS": "0",
|
| 121 |
+
"manager_set-MAX_NUM_FORMS": "0",
|
| 122 |
+
"manager_set-0-name": "Guido Van Rossum",
|
| 123 |
+
}
|
| 124 |
+
restaurant = User()
|
| 125 |
+
form = Form(data)
|
| 126 |
+
if form.is_valid():
|
| 127 |
+
restaurant = form.save()
|
| 128 |
+
else:
|
| 129 |
+
self.fail("Errors found on form:%s" % form_set)
|
| 130 |
+
|
| 131 |
+
form_set = FormSet(data, instance=restaurant)
|
| 132 |
+
if form_set.is_valid():
|
| 133 |
+
form_set.save()
|
| 134 |
+
manager = Manager.objects.values()
|
| 135 |
+
self.assertEqual(manager[0]["name"], "Guido Van Rossum")
|
| 136 |
+
else:
|
| 137 |
+
self.fail("Errors found on formset:%s" % form_set.errors)
|
| 138 |
+
|
| 139 |
+
# Now update the Manager instance
|
| 140 |
+
data = {
|
| 141 |
+
"manager_set-TOTAL_FORMS": "1",
|
| 142 |
+
"manager_set-INITIAL_FORMS": "1",
|
| 143 |
+
"manager_set-MAX_NUM_FORMS": "0",
|
| 144 |
+
"manager_set-0-id": str(manager[0]["id"]),
|
| 145 |
+
"manager_set-0-name": "Terry Gilliam",
|
| 146 |
+
}
|
| 147 |
+
form_set = FormSet(data, instance=restaurant)
|
| 148 |
+
if form_set.is_valid():
|
| 149 |
+
form_set.save()
|
| 150 |
+
manager = Manager.objects.values()
|
| 151 |
+
self.assertEqual(manager[0]["name"], "Terry Gilliam")
|
| 152 |
+
else:
|
| 153 |
+
self.fail("Errors found on formset:%s" % form_set.errors)
|
| 154 |
+
|
| 155 |
+
# Now add a new Manager instance
|
| 156 |
+
data = {
|
| 157 |
+
"manager_set-TOTAL_FORMS": "2",
|
| 158 |
+
"manager_set-INITIAL_FORMS": "1",
|
| 159 |
+
"manager_set-MAX_NUM_FORMS": "0",
|
| 160 |
+
"manager_set-0-id": str(manager[0]["id"]),
|
| 161 |
+
"manager_set-0-name": "Terry Gilliam",
|
| 162 |
+
"manager_set-1-name": "John Cleese",
|
| 163 |
+
}
|
| 164 |
+
form_set = FormSet(data, instance=restaurant)
|
| 165 |
+
if form_set.is_valid():
|
| 166 |
+
form_set.save()
|
| 167 |
+
manager = Manager.objects.values().order_by("name")
|
| 168 |
+
self.assertEqual(manager[0]["name"], "John Cleese")
|
| 169 |
+
self.assertEqual(manager[1]["name"], "Terry Gilliam")
|
| 170 |
+
else:
|
| 171 |
+
self.fail("Errors found on formset:%s" % form_set.errors)
|
| 172 |
+
|
| 173 |
+
def test_inline_model_with_to_field(self):
|
| 174 |
+
"""
|
| 175 |
+
#13794 --- An inline model with a to_field of a formset with instance
|
| 176 |
+
has working relations.
|
| 177 |
+
"""
|
| 178 |
+
FormSet = inlineformset_factory(User, UserSite, exclude=("is_superuser",))
|
| 179 |
+
|
| 180 |
+
user = User.objects.create(username="guido", serial=1337)
|
| 181 |
+
UserSite.objects.create(user=user, data=10)
|
| 182 |
+
formset = FormSet(instance=user)
|
| 183 |
+
|
| 184 |
+
# Testing the inline model's relation
|
| 185 |
+
self.assertEqual(formset[0].instance.user_id, "guido")
|
| 186 |
+
|
| 187 |
+
def test_inline_model_with_primary_to_field(self):
|
| 188 |
+
"""An inline model with a OneToOneField with to_field & primary key."""
|
| 189 |
+
FormSet = inlineformset_factory(
|
| 190 |
+
User, UserPreferences, exclude=("is_superuser",)
|
| 191 |
+
)
|
| 192 |
+
user = User.objects.create(username="guido", serial=1337)
|
| 193 |
+
UserPreferences.objects.create(user=user, favorite_number=10)
|
| 194 |
+
formset = FormSet(instance=user)
|
| 195 |
+
self.assertEqual(formset[0].fields["user"].initial, "guido")
|
| 196 |
+
|
| 197 |
+
def test_inline_model_with_to_field_to_rel(self):
|
| 198 |
+
"""
|
| 199 |
+
#13794 --- An inline model with a to_field to a related field of a
|
| 200 |
+
formset with instance has working relations.
|
| 201 |
+
"""
|
| 202 |
+
FormSet = inlineformset_factory(UserProfile, ProfileNetwork, exclude=[])
|
| 203 |
+
|
| 204 |
+
user = User.objects.create(username="guido", serial=1337, pk=1)
|
| 205 |
+
self.assertEqual(user.pk, 1)
|
| 206 |
+
profile = UserProfile.objects.create(user=user, about="about", pk=2)
|
| 207 |
+
self.assertEqual(profile.pk, 2)
|
| 208 |
+
ProfileNetwork.objects.create(profile=profile, network=10, identifier=10)
|
| 209 |
+
formset = FormSet(instance=profile)
|
| 210 |
+
|
| 211 |
+
# Testing the inline model's relation
|
| 212 |
+
self.assertEqual(formset[0].instance.profile_id, 1)
|
| 213 |
+
|
| 214 |
+
def test_formset_with_none_instance(self):
|
| 215 |
+
"A formset with instance=None can be created. Regression for #11872"
|
| 216 |
+
Form = modelform_factory(User, fields="__all__")
|
| 217 |
+
FormSet = inlineformset_factory(User, UserSite, fields="__all__")
|
| 218 |
+
|
| 219 |
+
# Instantiate the Form and FormSet to prove
|
| 220 |
+
# you can create a formset with an instance of None
|
| 221 |
+
Form(instance=None)
|
| 222 |
+
FormSet(instance=None)
|
| 223 |
+
|
| 224 |
+
def test_empty_fields_on_modelformset(self):
|
| 225 |
+
"""
|
| 226 |
+
No fields passed to modelformset_factory() should result in no fields
|
| 227 |
+
on returned forms except for the id (#14119).
|
| 228 |
+
"""
|
| 229 |
+
UserFormSet = modelformset_factory(User, fields=())
|
| 230 |
+
formset = UserFormSet()
|
| 231 |
+
for form in formset.forms:
|
| 232 |
+
self.assertIn("id", form.fields)
|
| 233 |
+
self.assertEqual(len(form.fields), 1)
|
| 234 |
+
|
| 235 |
+
def test_save_as_new_with_new_inlines(self):
|
| 236 |
+
"""
|
| 237 |
+
Existing and new inlines are saved with save_as_new.
|
| 238 |
+
|
| 239 |
+
Regression for #14938.
|
| 240 |
+
"""
|
| 241 |
+
efnet = Network.objects.create(name="EFNet")
|
| 242 |
+
host1 = Host.objects.create(hostname="irc.he.net", network=efnet)
|
| 243 |
+
|
| 244 |
+
HostFormSet = inlineformset_factory(Network, Host, fields="__all__")
|
| 245 |
+
|
| 246 |
+
# Add a new host, modify previous host, and save-as-new
|
| 247 |
+
data = {
|
| 248 |
+
"host_set-TOTAL_FORMS": "2",
|
| 249 |
+
"host_set-INITIAL_FORMS": "1",
|
| 250 |
+
"host_set-MAX_NUM_FORMS": "0",
|
| 251 |
+
"host_set-0-id": str(host1.id),
|
| 252 |
+
"host_set-0-hostname": "tranquility.hub.dal.net",
|
| 253 |
+
"host_set-1-hostname": "matrix.de.eu.dal.net",
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
# To save a formset as new, it needs a new hub instance
|
| 257 |
+
dalnet = Network.objects.create(name="DALnet")
|
| 258 |
+
formset = HostFormSet(data, instance=dalnet, save_as_new=True)
|
| 259 |
+
|
| 260 |
+
self.assertTrue(formset.is_valid())
|
| 261 |
+
formset.save()
|
| 262 |
+
self.assertQuerySetEqual(
|
| 263 |
+
dalnet.host_set.order_by("hostname"),
|
| 264 |
+
Host.objects.filter(
|
| 265 |
+
hostname__in=[
|
| 266 |
+
"matrix.de.eu.dal.net",
|
| 267 |
+
"tranquility.hub.dal.net",
|
| 268 |
+
]
|
| 269 |
+
).order_by("hostname"),
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
def test_initial_data(self):
|
| 273 |
+
user = User.objects.create(username="bibi", serial=1)
|
| 274 |
+
UserSite.objects.create(user=user, data=7)
|
| 275 |
+
FormSet = inlineformset_factory(User, UserSite, extra=2, fields="__all__")
|
| 276 |
+
|
| 277 |
+
formset = FormSet(instance=user, initial=[{"data": 41}, {"data": 42}])
|
| 278 |
+
self.assertEqual(formset.forms[0].initial["data"], 7)
|
| 279 |
+
self.assertEqual(formset.extra_forms[0].initial["data"], 41)
|
| 280 |
+
self.assertIn('value="42"', formset.extra_forms[1].as_p())
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class FormsetTests(TestCase):
|
| 284 |
+
def test_error_class(self):
|
| 285 |
+
"""
|
| 286 |
+
Test the type of Formset and Form error attributes
|
| 287 |
+
"""
|
| 288 |
+
Formset = modelformset_factory(User, fields="__all__")
|
| 289 |
+
data = {
|
| 290 |
+
"form-TOTAL_FORMS": "2",
|
| 291 |
+
"form-INITIAL_FORMS": "0",
|
| 292 |
+
"form-MAX_NUM_FORMS": "0",
|
| 293 |
+
"form-0-id": "",
|
| 294 |
+
"form-0-username": "apollo13",
|
| 295 |
+
"form-0-serial": "1",
|
| 296 |
+
"form-1-id": "",
|
| 297 |
+
"form-1-username": "apollo13",
|
| 298 |
+
"form-1-serial": "2",
|
| 299 |
+
}
|
| 300 |
+
formset = Formset(data)
|
| 301 |
+
# check if the returned error classes are correct
|
| 302 |
+
# note: formset.errors returns a list as documented
|
| 303 |
+
self.assertIsInstance(formset.errors, list)
|
| 304 |
+
self.assertIsInstance(formset.non_form_errors(), ErrorList)
|
| 305 |
+
for form in formset.forms:
|
| 306 |
+
self.assertIsInstance(form.errors, ErrorDict)
|
| 307 |
+
self.assertIsInstance(form.non_field_errors(), ErrorList)
|
| 308 |
+
|
| 309 |
+
def test_initial_data(self):
|
| 310 |
+
User.objects.create(username="bibi", serial=1)
|
| 311 |
+
Formset = modelformset_factory(User, fields="__all__", extra=2)
|
| 312 |
+
formset = Formset(initial=[{"username": "apollo11"}, {"username": "apollo12"}])
|
| 313 |
+
self.assertEqual(formset.forms[0].initial["username"], "bibi")
|
| 314 |
+
self.assertEqual(formset.extra_forms[0].initial["username"], "apollo11")
|
| 315 |
+
self.assertIn('value="apollo12"', formset.extra_forms[1].as_p())
|
| 316 |
+
|
| 317 |
+
def test_extraneous_query_is_not_run(self):
|
| 318 |
+
Formset = modelformset_factory(Network, fields="__all__")
|
| 319 |
+
data = {
|
| 320 |
+
"test-TOTAL_FORMS": "1",
|
| 321 |
+
"test-INITIAL_FORMS": "0",
|
| 322 |
+
"test-MAX_NUM_FORMS": "",
|
| 323 |
+
"test-0-name": "Random Place",
|
| 324 |
+
}
|
| 325 |
+
with self.assertNumQueries(1):
|
| 326 |
+
formset = Formset(data, prefix="test")
|
| 327 |
+
formset.save()
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
class CustomWidget(forms.widgets.TextInput):
|
| 331 |
+
pass
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
class UserSiteForm(forms.ModelForm):
|
| 335 |
+
class Meta:
|
| 336 |
+
model = UserSite
|
| 337 |
+
fields = "__all__"
|
| 338 |
+
widgets = {
|
| 339 |
+
"id": CustomWidget,
|
| 340 |
+
"data": CustomWidget,
|
| 341 |
+
}
|
| 342 |
+
localized_fields = ("data",)
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class Callback:
|
| 346 |
+
def __init__(self):
|
| 347 |
+
self.log = []
|
| 348 |
+
|
| 349 |
+
def __call__(self, db_field, **kwargs):
|
| 350 |
+
self.log.append((db_field, kwargs))
|
| 351 |
+
return db_field.formfield(**kwargs)
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
class FormfieldCallbackTests(TestCase):
|
| 355 |
+
"""
|
| 356 |
+
Regression for #13095 and #17683: Using base forms with widgets
|
| 357 |
+
defined in Meta should not raise errors and BaseModelForm should respect
|
| 358 |
+
the specified pk widget.
|
| 359 |
+
"""
|
| 360 |
+
|
| 361 |
+
def test_inlineformset_factory_default(self):
|
| 362 |
+
Formset = inlineformset_factory(
|
| 363 |
+
User, UserSite, form=UserSiteForm, fields="__all__"
|
| 364 |
+
)
|
| 365 |
+
form = Formset().forms[0]
|
| 366 |
+
self.assertIsInstance(form["id"].field.widget, CustomWidget)
|
| 367 |
+
self.assertIsInstance(form["data"].field.widget, CustomWidget)
|
| 368 |
+
self.assertFalse(form.fields["id"].localize)
|
| 369 |
+
self.assertTrue(form.fields["data"].localize)
|
| 370 |
+
|
| 371 |
+
def test_modelformset_factory_default(self):
|
| 372 |
+
Formset = modelformset_factory(UserSite, form=UserSiteForm)
|
| 373 |
+
form = Formset().forms[0]
|
| 374 |
+
self.assertIsInstance(form["id"].field.widget, CustomWidget)
|
| 375 |
+
self.assertIsInstance(form["data"].field.widget, CustomWidget)
|
| 376 |
+
self.assertFalse(form.fields["id"].localize)
|
| 377 |
+
self.assertTrue(form.fields["data"].localize)
|
| 378 |
+
|
| 379 |
+
def assertCallbackCalled(self, callback):
|
| 380 |
+
id_field, user_field, data_field = UserSite._meta.fields
|
| 381 |
+
expected_log = [
|
| 382 |
+
(id_field, {"widget": CustomWidget}),
|
| 383 |
+
(user_field, {}),
|
| 384 |
+
(data_field, {"widget": CustomWidget, "localize": True}),
|
| 385 |
+
]
|
| 386 |
+
self.assertEqual(callback.log, expected_log)
|
| 387 |
+
|
| 388 |
+
def test_inlineformset_custom_callback(self):
|
| 389 |
+
callback = Callback()
|
| 390 |
+
inlineformset_factory(
|
| 391 |
+
User,
|
| 392 |
+
UserSite,
|
| 393 |
+
form=UserSiteForm,
|
| 394 |
+
formfield_callback=callback,
|
| 395 |
+
fields="__all__",
|
| 396 |
+
)
|
| 397 |
+
self.assertCallbackCalled(callback)
|
| 398 |
+
|
| 399 |
+
def test_modelformset_custom_callback(self):
|
| 400 |
+
callback = Callback()
|
| 401 |
+
modelformset_factory(UserSite, form=UserSiteForm, formfield_callback=callback)
|
| 402 |
+
self.assertCallbackCalled(callback)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
class BaseCustomDeleteFormSet(BaseFormSet):
|
| 406 |
+
"""
|
| 407 |
+
A formset mix-in that lets a form decide if it's to be deleted.
|
| 408 |
+
Works for BaseFormSets. Also works for ModelFormSets with #14099 fixed.
|
| 409 |
+
|
| 410 |
+
form.should_delete() is called. The formset delete field is also suppressed.
|
| 411 |
+
"""
|
| 412 |
+
|
| 413 |
+
def add_fields(self, form, index):
|
| 414 |
+
super().add_fields(form, index)
|
| 415 |
+
self.can_delete = True
|
| 416 |
+
if DELETION_FIELD_NAME in form.fields:
|
| 417 |
+
del form.fields[DELETION_FIELD_NAME]
|
| 418 |
+
|
| 419 |
+
def _should_delete_form(self, form):
|
| 420 |
+
return hasattr(form, "should_delete") and form.should_delete()
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class FormfieldShouldDeleteFormTests(TestCase):
|
| 424 |
+
"""
|
| 425 |
+
BaseModelFormSet should use ModelFormSet method _should_delete_form.
|
| 426 |
+
"""
|
| 427 |
+
|
| 428 |
+
class BaseCustomDeleteModelFormSet(BaseModelFormSet, BaseCustomDeleteFormSet):
|
| 429 |
+
"""Model FormSet with CustomDelete MixIn"""
|
| 430 |
+
|
| 431 |
+
class CustomDeleteUserForm(forms.ModelForm):
|
| 432 |
+
"""A model form with a 'should_delete' method"""
|
| 433 |
+
|
| 434 |
+
class Meta:
|
| 435 |
+
model = User
|
| 436 |
+
fields = "__all__"
|
| 437 |
+
|
| 438 |
+
def should_delete(self):
|
| 439 |
+
"""Delete form if odd serial."""
|
| 440 |
+
return self.instance.serial % 2 != 0
|
| 441 |
+
|
| 442 |
+
NormalFormset = modelformset_factory(
|
| 443 |
+
User, form=CustomDeleteUserForm, can_delete=True
|
| 444 |
+
)
|
| 445 |
+
DeleteFormset = modelformset_factory(
|
| 446 |
+
User, form=CustomDeleteUserForm, formset=BaseCustomDeleteModelFormSet
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
data = {
|
| 450 |
+
"form-TOTAL_FORMS": "4",
|
| 451 |
+
"form-INITIAL_FORMS": "0",
|
| 452 |
+
"form-MAX_NUM_FORMS": "4",
|
| 453 |
+
"form-0-username": "John",
|
| 454 |
+
"form-0-serial": "1",
|
| 455 |
+
"form-1-username": "Paul",
|
| 456 |
+
"form-1-serial": "2",
|
| 457 |
+
"form-2-username": "George",
|
| 458 |
+
"form-2-serial": "3",
|
| 459 |
+
"form-3-username": "Ringo",
|
| 460 |
+
"form-3-serial": "5",
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
delete_all_ids = {
|
| 464 |
+
"form-0-DELETE": "1",
|
| 465 |
+
"form-1-DELETE": "1",
|
| 466 |
+
"form-2-DELETE": "1",
|
| 467 |
+
"form-3-DELETE": "1",
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
def test_init_database(self):
|
| 471 |
+
"""Add test data to database via formset"""
|
| 472 |
+
formset = self.NormalFormset(self.data)
|
| 473 |
+
self.assertTrue(formset.is_valid())
|
| 474 |
+
self.assertEqual(len(formset.save()), 4)
|
| 475 |
+
|
| 476 |
+
def test_no_delete(self):
|
| 477 |
+
"""Verify base formset doesn't modify database"""
|
| 478 |
+
# reload database
|
| 479 |
+
self.test_init_database()
|
| 480 |
+
|
| 481 |
+
# pass standard data dict & see none updated
|
| 482 |
+
data = dict(self.data)
|
| 483 |
+
data["form-INITIAL_FORMS"] = 4
|
| 484 |
+
data.update(
|
| 485 |
+
{
|
| 486 |
+
"form-%d-id" % i: user.pk
|
| 487 |
+
for i, user in enumerate(User.objects.order_by("pk"))
|
| 488 |
+
}
|
| 489 |
+
)
|
| 490 |
+
formset = self.NormalFormset(data, queryset=User.objects.all())
|
| 491 |
+
self.assertTrue(formset.is_valid())
|
| 492 |
+
self.assertEqual(len(formset.save()), 0)
|
| 493 |
+
self.assertEqual(len(User.objects.all()), 4)
|
| 494 |
+
|
| 495 |
+
def test_all_delete(self):
|
| 496 |
+
"""Verify base formset honors DELETE field"""
|
| 497 |
+
# reload database
|
| 498 |
+
self.test_init_database()
|
| 499 |
+
|
| 500 |
+
# create data dict with all fields marked for deletion
|
| 501 |
+
data = dict(self.data)
|
| 502 |
+
data["form-INITIAL_FORMS"] = 4
|
| 503 |
+
data.update(
|
| 504 |
+
{"form-%d-id" % i: user.pk for i, user in enumerate(User.objects.all())}
|
| 505 |
+
)
|
| 506 |
+
data.update(self.delete_all_ids)
|
| 507 |
+
formset = self.NormalFormset(data, queryset=User.objects.all())
|
| 508 |
+
self.assertTrue(formset.is_valid())
|
| 509 |
+
self.assertEqual(len(formset.save()), 0)
|
| 510 |
+
self.assertEqual(len(User.objects.all()), 0)
|
| 511 |
+
|
| 512 |
+
def test_custom_delete(self):
|
| 513 |
+
"""Verify DeleteFormset ignores DELETE field and uses form method"""
|
| 514 |
+
# reload database
|
| 515 |
+
self.test_init_database()
|
| 516 |
+
|
| 517 |
+
# Create formset with custom Delete function
|
| 518 |
+
# create data dict with all fields marked for deletion
|
| 519 |
+
data = dict(self.data)
|
| 520 |
+
data["form-INITIAL_FORMS"] = 4
|
| 521 |
+
data.update(
|
| 522 |
+
{
|
| 523 |
+
"form-%d-id" % i: user.pk
|
| 524 |
+
for i, user in enumerate(User.objects.order_by("pk"))
|
| 525 |
+
}
|
| 526 |
+
)
|
| 527 |
+
data.update(self.delete_all_ids)
|
| 528 |
+
formset = self.DeleteFormset(data, queryset=User.objects.all())
|
| 529 |
+
|
| 530 |
+
# Three with odd serial values were deleted.
|
| 531 |
+
self.assertTrue(formset.is_valid())
|
| 532 |
+
self.assertEqual(len(formset.save()), 0)
|
| 533 |
+
self.assertEqual(User.objects.count(), 1)
|
| 534 |
+
|
| 535 |
+
# No odd serial values left.
|
| 536 |
+
odd_serials = [user.serial for user in User.objects.all() if user.serial % 2]
|
| 537 |
+
self.assertEqual(len(odd_serials), 0)
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
class RedeleteTests(TestCase):
|
| 541 |
+
def test_resubmit(self):
|
| 542 |
+
u = User.objects.create(username="foo", serial=1)
|
| 543 |
+
us = UserSite.objects.create(user=u, data=7)
|
| 544 |
+
formset_cls = inlineformset_factory(User, UserSite, fields="__all__")
|
| 545 |
+
data = {
|
| 546 |
+
"serial": "1",
|
| 547 |
+
"username": "foo",
|
| 548 |
+
"usersite_set-TOTAL_FORMS": "1",
|
| 549 |
+
"usersite_set-INITIAL_FORMS": "1",
|
| 550 |
+
"usersite_set-MAX_NUM_FORMS": "1",
|
| 551 |
+
"usersite_set-0-id": str(us.pk),
|
| 552 |
+
"usersite_set-0-data": "7",
|
| 553 |
+
"usersite_set-0-user": "foo",
|
| 554 |
+
"usersite_set-0-DELETE": "1",
|
| 555 |
+
}
|
| 556 |
+
formset = formset_cls(data, instance=u)
|
| 557 |
+
self.assertTrue(formset.is_valid())
|
| 558 |
+
formset.save()
|
| 559 |
+
self.assertEqual(UserSite.objects.count(), 0)
|
| 560 |
+
formset = formset_cls(data, instance=u)
|
| 561 |
+
# Even if the "us" object isn't in the DB any more, the form
|
| 562 |
+
# validates.
|
| 563 |
+
self.assertTrue(formset.is_valid())
|
| 564 |
+
formset.save()
|
| 565 |
+
self.assertEqual(UserSite.objects.count(), 0)
|
| 566 |
+
|
| 567 |
+
def test_delete_already_deleted(self):
|
| 568 |
+
u = User.objects.create(username="foo", serial=1)
|
| 569 |
+
us = UserSite.objects.create(user=u, data=7)
|
| 570 |
+
formset_cls = inlineformset_factory(User, UserSite, fields="__all__")
|
| 571 |
+
data = {
|
| 572 |
+
"serial": "1",
|
| 573 |
+
"username": "foo",
|
| 574 |
+
"usersite_set-TOTAL_FORMS": "1",
|
| 575 |
+
"usersite_set-INITIAL_FORMS": "1",
|
| 576 |
+
"usersite_set-MAX_NUM_FORMS": "1",
|
| 577 |
+
"usersite_set-0-id": str(us.pk),
|
| 578 |
+
"usersite_set-0-data": "7",
|
| 579 |
+
"usersite_set-0-user": "foo",
|
| 580 |
+
"usersite_set-0-DELETE": "1",
|
| 581 |
+
}
|
| 582 |
+
formset = formset_cls(data, instance=u)
|
| 583 |
+
us.delete()
|
| 584 |
+
self.assertTrue(formset.is_valid())
|
| 585 |
+
formset.save()
|
| 586 |
+
self.assertEqual(UserSite.objects.count(), 0)
|
testbed/django__django/tests/model_indexes/__init__.py
ADDED
|
File without changes
|
testbed/django__django/tests/model_indexes/models.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Book(models.Model):
|
| 5 |
+
title = models.CharField(max_length=50)
|
| 6 |
+
author = models.CharField(max_length=50)
|
| 7 |
+
pages = models.IntegerField(db_column="page_count")
|
| 8 |
+
shortcut = models.CharField(max_length=50, db_tablespace="idx_tbls")
|
| 9 |
+
isbn = models.CharField(max_length=50, db_tablespace="idx_tbls")
|
| 10 |
+
barcode = models.CharField(max_length=31)
|
| 11 |
+
|
| 12 |
+
class Meta:
|
| 13 |
+
indexes = [
|
| 14 |
+
models.Index(fields=["title"]),
|
| 15 |
+
models.Index(fields=["isbn", "id"]),
|
| 16 |
+
models.Index(
|
| 17 |
+
fields=["barcode"], name="%(app_label)s_%(class)s_barcode_idx"
|
| 18 |
+
),
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class AbstractModel(models.Model):
|
| 23 |
+
name = models.CharField(max_length=50)
|
| 24 |
+
shortcut = models.CharField(max_length=3)
|
| 25 |
+
|
| 26 |
+
class Meta:
|
| 27 |
+
abstract = True
|
| 28 |
+
indexes = [
|
| 29 |
+
models.Index(fields=["name"]),
|
| 30 |
+
models.Index(fields=["shortcut"], name="%(app_label)s_%(class)s_idx"),
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class ChildModel1(AbstractModel):
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class ChildModel2(AbstractModel):
|
| 39 |
+
pass
|
testbed/django__django/tests/model_indexes/tests.py
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from unittest import mock
|
| 2 |
+
|
| 3 |
+
from django.conf import settings
|
| 4 |
+
from django.db import connection, models
|
| 5 |
+
from django.db.models.functions import Lower, Upper
|
| 6 |
+
from django.test import SimpleTestCase, TestCase, override_settings, skipUnlessDBFeature
|
| 7 |
+
from django.test.utils import isolate_apps
|
| 8 |
+
|
| 9 |
+
from .models import Book, ChildModel1, ChildModel2
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class SimpleIndexesTests(SimpleTestCase):
|
| 13 |
+
def test_suffix(self):
|
| 14 |
+
self.assertEqual(models.Index.suffix, "idx")
|
| 15 |
+
|
| 16 |
+
def test_repr(self):
|
| 17 |
+
index = models.Index(fields=["title"])
|
| 18 |
+
named_index = models.Index(fields=["title"], name="title_idx")
|
| 19 |
+
multi_col_index = models.Index(fields=["title", "author"])
|
| 20 |
+
partial_index = models.Index(
|
| 21 |
+
fields=["title"], name="long_books_idx", condition=models.Q(pages__gt=400)
|
| 22 |
+
)
|
| 23 |
+
covering_index = models.Index(
|
| 24 |
+
fields=["title"],
|
| 25 |
+
name="include_idx",
|
| 26 |
+
include=["author", "pages"],
|
| 27 |
+
)
|
| 28 |
+
opclasses_index = models.Index(
|
| 29 |
+
fields=["headline", "body"],
|
| 30 |
+
name="opclasses_idx",
|
| 31 |
+
opclasses=["varchar_pattern_ops", "text_pattern_ops"],
|
| 32 |
+
)
|
| 33 |
+
func_index = models.Index(Lower("title"), "subtitle", name="book_func_idx")
|
| 34 |
+
tablespace_index = models.Index(
|
| 35 |
+
fields=["title"],
|
| 36 |
+
db_tablespace="idx_tbls",
|
| 37 |
+
name="book_tablespace_idx",
|
| 38 |
+
)
|
| 39 |
+
self.assertEqual(repr(index), "<Index: fields=['title']>")
|
| 40 |
+
self.assertEqual(
|
| 41 |
+
repr(named_index),
|
| 42 |
+
"<Index: fields=['title'] name='title_idx'>",
|
| 43 |
+
)
|
| 44 |
+
self.assertEqual(repr(multi_col_index), "<Index: fields=['title', 'author']>")
|
| 45 |
+
self.assertEqual(
|
| 46 |
+
repr(partial_index),
|
| 47 |
+
"<Index: fields=['title'] name='long_books_idx' "
|
| 48 |
+
"condition=(AND: ('pages__gt', 400))>",
|
| 49 |
+
)
|
| 50 |
+
self.assertEqual(
|
| 51 |
+
repr(covering_index),
|
| 52 |
+
"<Index: fields=['title'] name='include_idx' "
|
| 53 |
+
"include=('author', 'pages')>",
|
| 54 |
+
)
|
| 55 |
+
self.assertEqual(
|
| 56 |
+
repr(opclasses_index),
|
| 57 |
+
"<Index: fields=['headline', 'body'] name='opclasses_idx' "
|
| 58 |
+
"opclasses=['varchar_pattern_ops', 'text_pattern_ops']>",
|
| 59 |
+
)
|
| 60 |
+
self.assertEqual(
|
| 61 |
+
repr(func_index),
|
| 62 |
+
"<Index: expressions=(Lower(F(title)), F(subtitle)) "
|
| 63 |
+
"name='book_func_idx'>",
|
| 64 |
+
)
|
| 65 |
+
self.assertEqual(
|
| 66 |
+
repr(tablespace_index),
|
| 67 |
+
"<Index: fields=['title'] name='book_tablespace_idx' "
|
| 68 |
+
"db_tablespace='idx_tbls'>",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
def test_eq(self):
|
| 72 |
+
index = models.Index(fields=["title"])
|
| 73 |
+
same_index = models.Index(fields=["title"])
|
| 74 |
+
another_index = models.Index(fields=["title", "author"])
|
| 75 |
+
index.model = Book
|
| 76 |
+
same_index.model = Book
|
| 77 |
+
another_index.model = Book
|
| 78 |
+
self.assertEqual(index, same_index)
|
| 79 |
+
self.assertEqual(index, mock.ANY)
|
| 80 |
+
self.assertNotEqual(index, another_index)
|
| 81 |
+
|
| 82 |
+
def test_eq_func(self):
|
| 83 |
+
index = models.Index(Lower("title"), models.F("author"), name="book_func_idx")
|
| 84 |
+
same_index = models.Index(Lower("title"), "author", name="book_func_idx")
|
| 85 |
+
another_index = models.Index(Lower("title"), name="book_func_idx")
|
| 86 |
+
self.assertEqual(index, same_index)
|
| 87 |
+
self.assertEqual(index, mock.ANY)
|
| 88 |
+
self.assertNotEqual(index, another_index)
|
| 89 |
+
|
| 90 |
+
def test_index_fields_type(self):
|
| 91 |
+
with self.assertRaisesMessage(
|
| 92 |
+
ValueError, "Index.fields must be a list or tuple."
|
| 93 |
+
):
|
| 94 |
+
models.Index(fields="title")
|
| 95 |
+
|
| 96 |
+
def test_index_fields_strings(self):
|
| 97 |
+
msg = "Index.fields must contain only strings with field names."
|
| 98 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 99 |
+
models.Index(fields=[models.F("title")])
|
| 100 |
+
|
| 101 |
+
def test_fields_tuple(self):
|
| 102 |
+
self.assertEqual(models.Index(fields=("title",)).fields, ["title"])
|
| 103 |
+
|
| 104 |
+
def test_requires_field_or_expression(self):
|
| 105 |
+
msg = "At least one field or expression is required to define an index."
|
| 106 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 107 |
+
models.Index()
|
| 108 |
+
|
| 109 |
+
def test_expressions_and_fields_mutually_exclusive(self):
|
| 110 |
+
msg = "Index.fields and expressions are mutually exclusive."
|
| 111 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 112 |
+
models.Index(Upper("foo"), fields=["field"])
|
| 113 |
+
|
| 114 |
+
def test_opclasses_requires_index_name(self):
|
| 115 |
+
with self.assertRaisesMessage(
|
| 116 |
+
ValueError, "An index must be named to use opclasses."
|
| 117 |
+
):
|
| 118 |
+
models.Index(opclasses=["jsonb_path_ops"])
|
| 119 |
+
|
| 120 |
+
def test_opclasses_requires_list_or_tuple(self):
|
| 121 |
+
with self.assertRaisesMessage(
|
| 122 |
+
ValueError, "Index.opclasses must be a list or tuple."
|
| 123 |
+
):
|
| 124 |
+
models.Index(
|
| 125 |
+
name="test_opclass", fields=["field"], opclasses="jsonb_path_ops"
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
def test_opclasses_and_fields_same_length(self):
|
| 129 |
+
msg = "Index.fields and Index.opclasses must have the same number of elements."
|
| 130 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 131 |
+
models.Index(
|
| 132 |
+
name="test_opclass",
|
| 133 |
+
fields=["field", "other"],
|
| 134 |
+
opclasses=["jsonb_path_ops"],
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
def test_condition_requires_index_name(self):
|
| 138 |
+
with self.assertRaisesMessage(
|
| 139 |
+
ValueError, "An index must be named to use condition."
|
| 140 |
+
):
|
| 141 |
+
models.Index(condition=models.Q(pages__gt=400))
|
| 142 |
+
|
| 143 |
+
def test_expressions_requires_index_name(self):
|
| 144 |
+
msg = "An index must be named to use expressions."
|
| 145 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 146 |
+
models.Index(Lower("field"))
|
| 147 |
+
|
| 148 |
+
def test_expressions_with_opclasses(self):
|
| 149 |
+
msg = (
|
| 150 |
+
"Index.opclasses cannot be used with expressions. Use "
|
| 151 |
+
"django.contrib.postgres.indexes.OpClass() instead."
|
| 152 |
+
)
|
| 153 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 154 |
+
models.Index(
|
| 155 |
+
Lower("field"),
|
| 156 |
+
name="test_func_opclass",
|
| 157 |
+
opclasses=["jsonb_path_ops"],
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
def test_condition_must_be_q(self):
|
| 161 |
+
with self.assertRaisesMessage(
|
| 162 |
+
ValueError, "Index.condition must be a Q instance."
|
| 163 |
+
):
|
| 164 |
+
models.Index(condition="invalid", name="long_book_idx")
|
| 165 |
+
|
| 166 |
+
def test_include_requires_list_or_tuple(self):
|
| 167 |
+
msg = "Index.include must be a list or tuple."
|
| 168 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 169 |
+
models.Index(name="test_include", fields=["field"], include="other")
|
| 170 |
+
|
| 171 |
+
def test_include_requires_index_name(self):
|
| 172 |
+
msg = "A covering index must be named."
|
| 173 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 174 |
+
models.Index(fields=["field"], include=["other"])
|
| 175 |
+
|
| 176 |
+
def test_name_auto_generation(self):
|
| 177 |
+
index = models.Index(fields=["author"])
|
| 178 |
+
index.set_name_with_model(Book)
|
| 179 |
+
self.assertEqual(index.name, "model_index_author_0f5565_idx")
|
| 180 |
+
|
| 181 |
+
# '-' for DESC columns should be accounted for in the index name.
|
| 182 |
+
index = models.Index(fields=["-author"])
|
| 183 |
+
index.set_name_with_model(Book)
|
| 184 |
+
self.assertEqual(index.name, "model_index_author_708765_idx")
|
| 185 |
+
|
| 186 |
+
# fields may be truncated in the name. db_column is used for naming.
|
| 187 |
+
long_field_index = models.Index(fields=["pages"])
|
| 188 |
+
long_field_index.set_name_with_model(Book)
|
| 189 |
+
self.assertEqual(long_field_index.name, "model_index_page_co_69235a_idx")
|
| 190 |
+
|
| 191 |
+
# suffix can't be longer than 3 characters.
|
| 192 |
+
long_field_index.suffix = "suff"
|
| 193 |
+
msg = (
|
| 194 |
+
"Index too long for multiple database support. Is self.suffix "
|
| 195 |
+
"longer than 3 characters?"
|
| 196 |
+
)
|
| 197 |
+
with self.assertRaisesMessage(ValueError, msg):
|
| 198 |
+
long_field_index.set_name_with_model(Book)
|
| 199 |
+
|
| 200 |
+
@isolate_apps("model_indexes")
|
| 201 |
+
def test_name_auto_generation_with_quoted_db_table(self):
|
| 202 |
+
class QuotedDbTable(models.Model):
|
| 203 |
+
name = models.CharField(max_length=50)
|
| 204 |
+
|
| 205 |
+
class Meta:
|
| 206 |
+
db_table = '"t_quoted"'
|
| 207 |
+
|
| 208 |
+
index = models.Index(fields=["name"])
|
| 209 |
+
index.set_name_with_model(QuotedDbTable)
|
| 210 |
+
self.assertEqual(index.name, "t_quoted_name_e4ed1b_idx")
|
| 211 |
+
|
| 212 |
+
def test_deconstruction(self):
|
| 213 |
+
index = models.Index(fields=["title"], db_tablespace="idx_tbls")
|
| 214 |
+
index.set_name_with_model(Book)
|
| 215 |
+
path, args, kwargs = index.deconstruct()
|
| 216 |
+
self.assertEqual(path, "django.db.models.Index")
|
| 217 |
+
self.assertEqual(args, ())
|
| 218 |
+
self.assertEqual(
|
| 219 |
+
kwargs,
|
| 220 |
+
{
|
| 221 |
+
"fields": ["title"],
|
| 222 |
+
"name": "model_index_title_196f42_idx",
|
| 223 |
+
"db_tablespace": "idx_tbls",
|
| 224 |
+
},
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
def test_deconstruct_with_condition(self):
|
| 228 |
+
index = models.Index(
|
| 229 |
+
name="big_book_index",
|
| 230 |
+
fields=["title"],
|
| 231 |
+
condition=models.Q(pages__gt=400),
|
| 232 |
+
)
|
| 233 |
+
index.set_name_with_model(Book)
|
| 234 |
+
path, args, kwargs = index.deconstruct()
|
| 235 |
+
self.assertEqual(path, "django.db.models.Index")
|
| 236 |
+
self.assertEqual(args, ())
|
| 237 |
+
self.assertEqual(
|
| 238 |
+
kwargs,
|
| 239 |
+
{
|
| 240 |
+
"fields": ["title"],
|
| 241 |
+
"name": "model_index_title_196f42_idx",
|
| 242 |
+
"condition": models.Q(pages__gt=400),
|
| 243 |
+
},
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
def test_deconstruct_with_include(self):
|
| 247 |
+
index = models.Index(
|
| 248 |
+
name="book_include_idx",
|
| 249 |
+
fields=["title"],
|
| 250 |
+
include=["author"],
|
| 251 |
+
)
|
| 252 |
+
index.set_name_with_model(Book)
|
| 253 |
+
path, args, kwargs = index.deconstruct()
|
| 254 |
+
self.assertEqual(path, "django.db.models.Index")
|
| 255 |
+
self.assertEqual(args, ())
|
| 256 |
+
self.assertEqual(
|
| 257 |
+
kwargs,
|
| 258 |
+
{
|
| 259 |
+
"fields": ["title"],
|
| 260 |
+
"name": "model_index_title_196f42_idx",
|
| 261 |
+
"include": ("author",),
|
| 262 |
+
},
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
def test_deconstruct_with_expressions(self):
|
| 266 |
+
index = models.Index(Upper("title"), name="book_func_idx")
|
| 267 |
+
path, args, kwargs = index.deconstruct()
|
| 268 |
+
self.assertEqual(path, "django.db.models.Index")
|
| 269 |
+
self.assertEqual(args, (Upper("title"),))
|
| 270 |
+
self.assertEqual(kwargs, {"name": "book_func_idx"})
|
| 271 |
+
|
| 272 |
+
def test_clone(self):
|
| 273 |
+
index = models.Index(fields=["title"])
|
| 274 |
+
new_index = index.clone()
|
| 275 |
+
self.assertIsNot(index, new_index)
|
| 276 |
+
self.assertEqual(index.fields, new_index.fields)
|
| 277 |
+
|
| 278 |
+
def test_clone_with_expressions(self):
|
| 279 |
+
index = models.Index(Upper("title"), name="book_func_idx")
|
| 280 |
+
new_index = index.clone()
|
| 281 |
+
self.assertIsNot(index, new_index)
|
| 282 |
+
self.assertEqual(index.expressions, new_index.expressions)
|
| 283 |
+
|
| 284 |
+
def test_name_set(self):
|
| 285 |
+
index_names = [index.name for index in Book._meta.indexes]
|
| 286 |
+
self.assertCountEqual(
|
| 287 |
+
index_names,
|
| 288 |
+
[
|
| 289 |
+
"model_index_title_196f42_idx",
|
| 290 |
+
"model_index_isbn_34f975_idx",
|
| 291 |
+
"model_indexes_book_barcode_idx",
|
| 292 |
+
],
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
def test_abstract_children(self):
|
| 296 |
+
index_names = [index.name for index in ChildModel1._meta.indexes]
|
| 297 |
+
self.assertEqual(
|
| 298 |
+
index_names,
|
| 299 |
+
["model_index_name_440998_idx", "model_indexes_childmodel1_idx"],
|
| 300 |
+
)
|
| 301 |
+
index_names = [index.name for index in ChildModel2._meta.indexes]
|
| 302 |
+
self.assertEqual(
|
| 303 |
+
index_names,
|
| 304 |
+
["model_index_name_b6c374_idx", "model_indexes_childmodel2_idx"],
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
@override_settings(DEFAULT_TABLESPACE=None)
|
| 309 |
+
class IndexesTests(TestCase):
|
| 310 |
+
@skipUnlessDBFeature("supports_tablespaces")
|
| 311 |
+
def test_db_tablespace(self):
|
| 312 |
+
editor = connection.schema_editor()
|
| 313 |
+
# Index with db_tablespace attribute.
|
| 314 |
+
for fields in [
|
| 315 |
+
# Field with db_tablespace specified on model.
|
| 316 |
+
["shortcut"],
|
| 317 |
+
# Field without db_tablespace specified on model.
|
| 318 |
+
["author"],
|
| 319 |
+
# Multi-column with db_tablespaces specified on model.
|
| 320 |
+
["shortcut", "isbn"],
|
| 321 |
+
# Multi-column without db_tablespace specified on model.
|
| 322 |
+
["title", "author"],
|
| 323 |
+
]:
|
| 324 |
+
with self.subTest(fields=fields):
|
| 325 |
+
index = models.Index(fields=fields, db_tablespace="idx_tbls2")
|
| 326 |
+
self.assertIn(
|
| 327 |
+
'"idx_tbls2"', str(index.create_sql(Book, editor)).lower()
|
| 328 |
+
)
|
| 329 |
+
# Indexes without db_tablespace attribute.
|
| 330 |
+
for fields in [["author"], ["shortcut", "isbn"], ["title", "author"]]:
|
| 331 |
+
with self.subTest(fields=fields):
|
| 332 |
+
index = models.Index(fields=fields)
|
| 333 |
+
# The DEFAULT_INDEX_TABLESPACE setting can't be tested because
|
| 334 |
+
# it's evaluated when the model class is defined. As a
|
| 335 |
+
# consequence, @override_settings doesn't work.
|
| 336 |
+
if settings.DEFAULT_INDEX_TABLESPACE:
|
| 337 |
+
self.assertIn(
|
| 338 |
+
'"%s"' % settings.DEFAULT_INDEX_TABLESPACE,
|
| 339 |
+
str(index.create_sql(Book, editor)).lower(),
|
| 340 |
+
)
|
| 341 |
+
else:
|
| 342 |
+
self.assertNotIn("TABLESPACE", str(index.create_sql(Book, editor)))
|
| 343 |
+
# Field with db_tablespace specified on the model and an index without
|
| 344 |
+
# db_tablespace.
|
| 345 |
+
index = models.Index(fields=["shortcut"])
|
| 346 |
+
self.assertIn('"idx_tbls"', str(index.create_sql(Book, editor)).lower())
|
| 347 |
+
|
| 348 |
+
@skipUnlessDBFeature("supports_tablespaces")
|
| 349 |
+
def test_func_with_tablespace(self):
|
| 350 |
+
# Functional index with db_tablespace attribute.
|
| 351 |
+
index = models.Index(
|
| 352 |
+
Lower("shortcut").desc(),
|
| 353 |
+
name="functional_tbls",
|
| 354 |
+
db_tablespace="idx_tbls2",
|
| 355 |
+
)
|
| 356 |
+
with connection.schema_editor() as editor:
|
| 357 |
+
sql = str(index.create_sql(Book, editor))
|
| 358 |
+
self.assertIn(editor.quote_name("idx_tbls2"), sql)
|
| 359 |
+
# Functional index without db_tablespace attribute.
|
| 360 |
+
index = models.Index(Lower("shortcut").desc(), name="functional_no_tbls")
|
| 361 |
+
with connection.schema_editor() as editor:
|
| 362 |
+
sql = str(index.create_sql(Book, editor))
|
| 363 |
+
# The DEFAULT_INDEX_TABLESPACE setting can't be tested because it's
|
| 364 |
+
# evaluated when the model class is defined. As a consequence,
|
| 365 |
+
# @override_settings doesn't work.
|
| 366 |
+
if settings.DEFAULT_INDEX_TABLESPACE:
|
| 367 |
+
self.assertIn(
|
| 368 |
+
editor.quote_name(settings.DEFAULT_INDEX_TABLESPACE),
|
| 369 |
+
sql,
|
| 370 |
+
)
|
| 371 |
+
else:
|
| 372 |
+
self.assertNotIn("TABLESPACE", sql)
|
testbed/django__django/tests/model_inheritance/__init__.py
ADDED
|
File without chang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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
XX. Model inheritance
|
| 3 |
+
|
| 4 |
+
Model inheritance exists in two varieties:
|
| 5 |
+
- abstract base classes which are a way of specifying common
|
| 6 |
+
information inherited by the subclasses. They don't exist as a separate
|
| 7 |
+
model.
|
| 8 |
+
- non-abstract base classes (the default), which are models in their own
|
| 9 |
+
right with their own database tables and everything. Their subclasses
|
| 10 |
+
have references back to them, created automatically.
|
| 11 |
+
|
| 12 |
+
Both styles are demonstrated here.
|
| 13 |
+
"""
|
| 14 |
+
from django.db import models
|
| 15 |
+
|
| 16 |
+
#
|
| 17 |
+
# Abstract base classes
|
| 18 |
+
#
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class CommonInfo(models.Model):
|
| 22 |
+
name = models.CharField(max_length=50)
|
| 23 |
+
age = models.PositiveIntegerField()
|
| 24 |
+
|
| 25 |
+
class Meta:
|
| 26 |
+
abstract = True
|
| 27 |
+
ordering = ["name"]
|
| 28 |
+
|
| 29 |
+
def __str__(self):
|
| 30 |
+
return "%s %s" % (self.__class__.__name__, self.name)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Worker(CommonInfo):
|
| 34 |
+
job = models.CharField(max_length=50)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class Student(CommonInfo):
|
| 38 |
+
school_class = models.CharField(max_length=10)
|
| 39 |
+
|
| 40 |
+
class Meta:
|
| 41 |
+
pass
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
#
|
| 45 |
+
# Abstract base classes with related models
|
| 46 |
+
#
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class Post(models.Model):
|
| 50 |
+
title = models.CharField(max_length=50)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class Attachment(models.Model):
|
| 54 |
+
post = models.ForeignKey(
|
| 55 |
+
Post,
|
| 56 |
+
models.CASCADE,
|
| 57 |
+
related_name="attached_%(class)s_set",
|
| 58 |
+
related_query_name="attached_%(app_label)s_%(class)ss",
|
| 59 |
+
)
|
| 60 |
+
content = models.TextField()
|
| 61 |
+
|
| 62 |
+
class Meta:
|
| 63 |
+
abstract = True
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class Comment(Attachment):
|
| 67 |
+
is_spam = models.BooleanField(default=False)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class Link(Attachment):
|
| 71 |
+
url = models.URLField()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
#
|
| 75 |
+
# Multi-table inheritance
|
| 76 |
+
#
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class Chef(models.Model):
|
| 80 |
+
name = models.CharField(max_length=50)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class Place(models.Model):
|
| 84 |
+
name = models.CharField(max_length=50)
|
| 85 |
+
address = models.CharField(max_length=80)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class Rating(models.Model):
|
| 89 |
+
rating = models.IntegerField(null=True, blank=True)
|
| 90 |
+
|
| 91 |
+
class Meta:
|
| 92 |
+
abstract = True
|
| 93 |
+
ordering = ["-rating"]
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class Restaurant(Place, Rating):
|
| 97 |
+
serves_hot_dogs = models.BooleanField(default=False)
|
| 98 |
+
serves_pizza = models.BooleanField(default=False)
|
| 99 |
+
chef = models.ForeignKey(Chef, models.SET_NULL, null=True, blank=True)
|
| 100 |
+
|
| 101 |
+
class Meta(Rating.Meta):
|
| 102 |
+
db_table = "my_restaurant"
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class ItalianRestaurant(Restaurant):
|
| 106 |
+
serves_gnocchi = models.BooleanField(default=False)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class ItalianRestaurantCommonParent(ItalianRestaurant, Place):
|
| 110 |
+
place_ptr_two = models.OneToOneField(
|
| 111 |
+
Place, on_delete=models.CASCADE, parent_link=True
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class Supplier(Place):
|
| 116 |
+
customers = models.ManyToManyField(Restaurant, related_name="provider")
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class CustomSupplier(Supplier):
|
| 120 |
+
pass
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class ParkingLot(Place):
|
| 124 |
+
# An explicit link to the parent (we can control the attribute name).
|
| 125 |
+
parent = models.OneToOneField(
|
| 126 |
+
Place, models.CASCADE, primary_key=True, parent_link=True
|
| 127 |
+
)
|
| 128 |
+
main_site = models.ForeignKey(Place, models.CASCADE, related_name="lot")
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
#
|
| 132 |
+
# Abstract base classes with related models where the sub-class has the
|
| 133 |
+
# same name in a different app and inherits from the same abstract base
|
| 134 |
+
# class.
|
| 135 |
+
# NOTE: The actual API tests for the following classes are in
|
| 136 |
+
# model_inheritance_same_model_name/models.py - They are defined
|
| 137 |
+
# here in order to have the name conflict between apps
|
| 138 |
+
#
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class Title(models.Model):
|
| 142 |
+
title = models.CharField(max_length=50)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
class NamedURL(models.Model):
|
| 146 |
+
title = models.ForeignKey(
|
| 147 |
+
Title, models.CASCADE, related_name="attached_%(app_label)s_%(class)s_set"
|
| 148 |
+
)
|
| 149 |
+
url = models.URLField()
|
| 150 |
+
|
| 151 |
+
class Meta:
|
| 152 |
+
abstract = True
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
class Mixin:
|
| 156 |
+
def __init__(self):
|
| 157 |
+
self.other_attr = 1
|
| 158 |
+
super().__init__()
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class MixinModel(models.Model, Mixin):
|
| 162 |
+
pass
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class Base(models.Model):
|
| 166 |
+
titles = models.ManyToManyField(Title)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class SubBase(Base):
|
| 170 |
+
sub_id = models.IntegerField(primary_key=True)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
class GrandParent(models.Model):
|
| 174 |
+
first_name = models.CharField(max_length=80)
|
| 175 |
+
last_name = models.CharField(max_length=80)
|
| 176 |
+
email = models.EmailField(unique=True)
|
| 177 |
+
place = models.ForeignKey(Place, models.CASCADE, null=True, related_name="+")
|
| 178 |
+
|
| 179 |
+
class Meta:
|
| 180 |
+
# Ordering used by test_inherited_ordering_pk_desc.
|
| 181 |
+
ordering = ["-pk"]
|
| 182 |
+
unique_together = ("first_name", "last_name")
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class Parent(GrandParent):
|
| 186 |
+
pass
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
class Child(Parent):
|
| 190 |
+
pass
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
class GrandChild(Child):
|
| 194 |
+
pass
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
class CommonAncestor(models.Model):
|
| 198 |
+
id = models.IntegerField(primary_key=True, default=1)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
class FirstParent(CommonAncestor):
|
| 202 |
+
first_ancestor = models.OneToOneField(
|
| 203 |
+
CommonAncestor, models.CASCADE, primary_key=True, parent_link=True
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
class SecondParent(CommonAncestor):
|
| 208 |
+
second_ancestor = models.OneToOneField(
|
| 209 |
+
CommonAncestor, models.CASCADE, primary_key=True, parent_link=True
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
class CommonChild(FirstParent, SecondParent):
|
| 214 |
+
pass
|
testbed/django__django/tests/model_inheritance/test_abstract_inheritance.py
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
| 2 |
+
from django.contrib.contenttypes.models import ContentType
|
| 3 |
+
from django.core.checks import Error
|
| 4 |
+
from django.core.exceptions import FieldDoesNotExist, FieldError
|
| 5 |
+
from django.db import models
|
| 6 |
+
from django.test import SimpleTestCase
|
| 7 |
+
from django.test.utils import isolate_apps
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@isolate_apps("model_inheritance")
|
| 11 |
+
class AbstractInheritanceTests(SimpleTestCase):
|
| 12 |
+
def test_single_parent(self):
|
| 13 |
+
class AbstractBase(models.Model):
|
| 14 |
+
name = models.CharField(max_length=30)
|
| 15 |
+
|
| 16 |
+
class Meta:
|
| 17 |
+
abstract = True
|
| 18 |
+
|
| 19 |
+
class AbstractDescendant(AbstractBase):
|
| 20 |
+
name = models.CharField(max_length=50)
|
| 21 |
+
|
| 22 |
+
class Meta:
|
| 23 |
+
abstract = True
|
| 24 |
+
|
| 25 |
+
class DerivedChild(AbstractBase):
|
| 26 |
+
name = models.CharField(max_length=50)
|
| 27 |
+
|
| 28 |
+
class DerivedGrandChild(AbstractDescendant):
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
self.assertEqual(AbstractDescendant._meta.get_field("name").max_length, 50)
|
| 32 |
+
self.assertEqual(DerivedChild._meta.get_field("name").max_length, 50)
|
| 33 |
+
self.assertEqual(DerivedGrandChild._meta.get_field("name").max_length, 50)
|
| 34 |
+
|
| 35 |
+
def test_multiple_inheritance_allows_inherited_field(self):
|
| 36 |
+
"""
|
| 37 |
+
Single layer multiple inheritance is as expected, deriving the
|
| 38 |
+
inherited field from the first base.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
class ParentA(models.Model):
|
| 42 |
+
name = models.CharField(max_length=255)
|
| 43 |
+
|
| 44 |
+
class Meta:
|
| 45 |
+
abstract = True
|
| 46 |
+
|
| 47 |
+
class ParentB(models.Model):
|
| 48 |
+
name = models.IntegerField()
|
| 49 |
+
|
| 50 |
+
class Meta:
|
| 51 |
+
abstract = True
|
| 52 |
+
|
| 53 |
+
class Child(ParentA, ParentB):
|
| 54 |
+
pass
|
| 55 |
+
|
| 56 |
+
self.assertEqual(Child.check(), [])
|
| 57 |
+
inherited_field = Child._meta.get_field("name")
|
| 58 |
+
self.assertIsInstance(inherited_field, models.CharField)
|
| 59 |
+
self.assertEqual(inherited_field.max_length, 255)
|
| 60 |
+
|
| 61 |
+
def test_diamond_shaped_multiple_inheritance_is_depth_first(self):
|
| 62 |
+
"""
|
| 63 |
+
In contrast to standard Python MRO, resolution of inherited fields is
|
| 64 |
+
strictly depth-first, rather than breadth-first in diamond-shaped cases.
|
| 65 |
+
|
| 66 |
+
This is because a copy of the parent field descriptor is placed onto
|
| 67 |
+
the model class in ModelBase.__new__(), rather than the attribute
|
| 68 |
+
lookup going via bases. (It only **looks** like inheritance.)
|
| 69 |
+
|
| 70 |
+
Here, Child inherits name from Root, rather than ParentB.
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
class Root(models.Model):
|
| 74 |
+
name = models.CharField(max_length=255)
|
| 75 |
+
|
| 76 |
+
class Meta:
|
| 77 |
+
abstract = True
|
| 78 |
+
|
| 79 |
+
class ParentA(Root):
|
| 80 |
+
class Meta:
|
| 81 |
+
abstract = True
|
| 82 |
+
|
| 83 |
+
class ParentB(Root):
|
| 84 |
+
name = models.IntegerField()
|
| 85 |
+
|
| 86 |
+
class Meta:
|
| 87 |
+
abstract = True
|
| 88 |
+
|
| 89 |
+
class Child(ParentA, ParentB):
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
self.assertEqual(Child.check(), [])
|
| 93 |
+
inherited_field = Child._meta.get_field("name")
|
| 94 |
+
self.assertIsInstance(inherited_field, models.CharField)
|
| 95 |
+
self.assertEqual(inherited_field.max_length, 255)
|
| 96 |
+
|
| 97 |
+
def test_target_field_may_be_pushed_down(self):
|
| 98 |
+
"""
|
| 99 |
+
Where the Child model needs to inherit a field from a different base
|
| 100 |
+
than that given by depth-first resolution, the target field can be
|
| 101 |
+
**pushed down** by being re-declared.
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
class Root(models.Model):
|
| 105 |
+
name = models.CharField(max_length=255)
|
| 106 |
+
|
| 107 |
+
class Meta:
|
| 108 |
+
abstract = True
|
| 109 |
+
|
| 110 |
+
class ParentA(Root):
|
| 111 |
+
class Meta:
|
| 112 |
+
abstract = True
|
| 113 |
+
|
| 114 |
+
class ParentB(Root):
|
| 115 |
+
name = models.IntegerField()
|
| 116 |
+
|
| 117 |
+
class Meta:
|
| 118 |
+
abstract = True
|
| 119 |
+
|
| 120 |
+
class Child(ParentA, ParentB):
|
| 121 |
+
name = models.IntegerField()
|
| 122 |
+
|
| 123 |
+
self.assertEqual(Child.check(), [])
|
| 124 |
+
inherited_field = Child._meta.get_field("name")
|
| 125 |
+
self.assertIsInstance(inherited_field, models.IntegerField)
|
| 126 |
+
|
| 127 |
+
def test_multiple_inheritance_cannot_shadow_concrete_inherited_field(self):
|
| 128 |
+
class ConcreteParent(models.Model):
|
| 129 |
+
name = models.CharField(max_length=255)
|
| 130 |
+
|
| 131 |
+
class AbstractParent(models.Model):
|
| 132 |
+
name = models.IntegerField()
|
| 133 |
+
|
| 134 |
+
class Meta:
|
| 135 |
+
abstract = True
|
| 136 |
+
|
| 137 |
+
class FirstChild(ConcreteParent, AbstractParent):
|
| 138 |
+
pass
|
| 139 |
+
|
| 140 |
+
class AnotherChild(AbstractParent, ConcreteParent):
|
| 141 |
+
pass
|
| 142 |
+
|
| 143 |
+
self.assertIsInstance(FirstChild._meta.get_field("name"), models.CharField)
|
| 144 |
+
self.assertEqual(
|
| 145 |
+
AnotherChild.check(),
|
| 146 |
+
[
|
| 147 |
+
Error(
|
| 148 |
+
"The field 'name' clashes with the field 'name' "
|
| 149 |
+
"from model 'model_inheritance.concreteparent'.",
|
| 150 |
+
obj=AnotherChild._meta.get_field("name"),
|
| 151 |
+
id="models.E006",
|
| 152 |
+
)
|
| 153 |
+
],
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
def test_virtual_field(self):
|
| 157 |
+
class RelationModel(models.Model):
|
| 158 |
+
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
| 159 |
+
object_id = models.PositiveIntegerField()
|
| 160 |
+
content_object = GenericForeignKey("content_type", "object_id")
|
| 161 |
+
|
| 162 |
+
class RelatedModelAbstract(models.Model):
|
| 163 |
+
field = GenericRelation(RelationModel)
|
| 164 |
+
|
| 165 |
+
class Meta:
|
| 166 |
+
abstract = True
|
| 167 |
+
|
| 168 |
+
class ModelAbstract(models.Model):
|
| 169 |
+
field = models.CharField(max_length=100)
|
| 170 |
+
|
| 171 |
+
class Meta:
|
| 172 |
+
abstract = True
|
| 173 |
+
|
| 174 |
+
class OverrideRelatedModelAbstract(RelatedModelAbstract):
|
| 175 |
+
field = models.CharField(max_length=100)
|
| 176 |
+
|
| 177 |
+
class ExtendModelAbstract(ModelAbstract):
|
| 178 |
+
field = GenericRelation(RelationModel)
|
| 179 |
+
|
| 180 |
+
self.assertIsInstance(
|
| 181 |
+
OverrideRelatedModelAbstract._meta.get_field("field"), models.CharField
|
| 182 |
+
)
|
| 183 |
+
self.assertIsInstance(
|
| 184 |
+
ExtendModelAbstract._meta.get_field("field"), GenericRelation
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
def test_cannot_override_indirect_abstract_field(self):
|
| 188 |
+
class AbstractBase(models.Model):
|
| 189 |
+
name = models.CharField(max_length=30)
|
| 190 |
+
|
| 191 |
+
class Meta:
|
| 192 |
+
abstract = True
|
| 193 |
+
|
| 194 |
+
class ConcreteDescendant(AbstractBase):
|
| 195 |
+
pass
|
| 196 |
+
|
| 197 |
+
msg = (
|
| 198 |
+
"Local field 'name' in class 'Descendant' clashes with field of "
|
| 199 |
+
"the same name from base class 'ConcreteDescendant'."
|
| 200 |
+
)
|
| 201 |
+
with self.assertRaisesMessage(FieldError, msg):
|
| 202 |
+
|
| 203 |
+
class Descendant(ConcreteDescendant):
|
| 204 |
+
name = models.IntegerField()
|
| 205 |
+
|
| 206 |
+
def test_override_field_with_attr(self):
|
| 207 |
+
class AbstractBase(models.Model):
|
| 208 |
+
first_name = models.CharField(max_length=50)
|
| 209 |
+
last_name = models.CharField(max_length=50)
|
| 210 |
+
middle_name = models.CharField(max_length=30)
|
| 211 |
+
full_name = models.CharField(max_length=150)
|
| 212 |
+
|
| 213 |
+
class Meta:
|
| 214 |
+
abstract = True
|
| 215 |
+
|
| 216 |
+
class Descendant(AbstractBase):
|
| 217 |
+
middle_name = None
|
| 218 |
+
|
| 219 |
+
def full_name(self):
|
| 220 |
+
return self.first_name + self.last_name
|
| 221 |
+
|
| 222 |
+
msg = "Descendant has no field named %r"
|
| 223 |
+
with self.assertRaisesMessage(FieldDoesNotExist, msg % "middle_name"):
|
| 224 |
+
Descendant._meta.get_field("middle_name")
|
| 225 |
+
|
| 226 |
+
with self.assertRaisesMessage(FieldDoesNotExist, msg % "full_name"):
|
| 227 |
+
Descendant._meta.get_field("full_name")
|
| 228 |
+
|
| 229 |
+
def test_overriding_field_removed_by_concrete_model(self):
|
| 230 |
+
class AbstractModel(models.Model):
|
| 231 |
+
foo = models.CharField(max_length=30)
|
| 232 |
+
|
| 233 |
+
class Meta:
|
| 234 |
+
abstract = True
|
| 235 |
+
|
| 236 |
+
class RemovedAbstractModelField(AbstractModel):
|
| 237 |
+
foo = None
|
| 238 |
+
|
| 239 |
+
class OverrideRemovedFieldByConcreteModel(RemovedAbstractModelField):
|
| 240 |
+
foo = models.CharField(max_length=50)
|
| 241 |
+
|
| 242 |
+
self.assertEqual(
|
| 243 |
+
OverrideRemovedFieldByConcreteModel._meta.get_field("foo").max_length, 50
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
def test_shadowed_fkey_id(self):
|
| 247 |
+
class Foo(models.Model):
|
| 248 |
+
pass
|
| 249 |
+
|
| 250 |
+
class AbstractBase(models.Model):
|
| 251 |
+
foo = models.ForeignKey(Foo, models.CASCADE)
|
| 252 |
+
|
| 253 |
+
class Meta:
|
| 254 |
+
abstract = True
|
| 255 |
+
|
| 256 |
+
class Descendant(AbstractBase):
|
| 257 |
+
foo_id = models.IntegerField()
|
| 258 |
+
|
| 259 |
+
self.assertEqual(
|
| 260 |
+
Descendant.check(),
|
| 261 |
+
[
|
| 262 |
+
Error(
|
| 263 |
+
"The field 'foo_id' clashes with the field 'foo' "
|
| 264 |
+
"from model 'model_inheritance.descendant'.",
|
| 265 |
+
obj=Descendant._meta.get_field("foo_id"),
|
| 266 |
+
id="models.E006",
|
| 267 |
+
)
|
| 268 |
+
],
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
def test_shadow_related_name_when_set_to_none(self):
|
| 272 |
+
class AbstractBase(models.Model):
|
| 273 |
+
bar = models.IntegerField()
|
| 274 |
+
|
| 275 |
+
class Meta:
|
| 276 |
+
abstract = True
|
| 277 |
+
|
| 278 |
+
class Foo(AbstractBase):
|
| 279 |
+
bar = None
|
| 280 |
+
foo = models.IntegerField()
|
| 281 |
+
|
| 282 |
+
class Bar(models.Model):
|
| 283 |
+
bar = models.ForeignKey(Foo, models.CASCADE, related_name="bar")
|
| 284 |
+
|
| 285 |
+
self.assertEqual(Bar.check(), [])
|
| 286 |
+
|
| 287 |
+
def test_reverse_foreign_key(self):
|
| 288 |
+
class AbstractBase(models.Model):
|
| 289 |
+
foo = models.CharField(max_length=100)
|
| 290 |
+
|
| 291 |
+
class Meta:
|
| 292 |
+
abstract = True
|
| 293 |
+
|
| 294 |
+
class Descendant(AbstractBase):
|
| 295 |
+
pass
|
| 296 |
+
|
| 297 |
+
class Foo(models.Model):
|
| 298 |
+
foo = models.ForeignKey(Descendant, models.CASCADE, related_name="foo")
|
| 299 |
+
|
| 300 |
+
self.assertEqual(
|
| 301 |
+
Foo._meta.get_field("foo").check(),
|
| 302 |
+
[
|
| 303 |
+
Error(
|
| 304 |
+
"Reverse accessor 'Descendant.foo' for "
|
| 305 |
+
"'model_inheritance.Foo.foo' clashes with field name "
|
| 306 |
+
"'model_inheritance.Descendant.foo'.",
|
| 307 |
+
hint=(
|
| 308 |
+
"Rename field 'model_inheritance.Descendant.foo', or "
|
| 309 |
+
"add/change a related_name argument to the definition "
|
| 310 |
+
"for field 'model_inheritance.Foo.foo'."
|
| 311 |
+
),
|
| 312 |
+
obj=Foo._meta.get_field("foo"),
|
| 313 |
+
id="fields.E302",
|
| 314 |
+
),
|
| 315 |
+
Error(
|
| 316 |
+
"Reverse query name for 'model_inheritance.Foo.foo' "
|
| 317 |
+
"clashes with field name "
|
| 318 |
+
"'model_inheritance.Descendant.foo'.",
|
| 319 |
+
hint=(
|
| 320 |
+
"Rename field 'model_inheritance.Descendant.foo', or "
|
| 321 |
+
"add/change a related_name argument to the definition "
|
| 322 |
+
"for field 'model_inheritance.Foo.foo'."
|
| 323 |
+
),
|
| 324 |
+
obj=Foo._meta.get_field("foo"),
|
| 325 |
+
id="fields.E303",
|
| 326 |
+
),
|
| 327 |
+
],
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
def test_multi_inheritance_field_clashes(self):
|
| 331 |
+
class AbstractBase(models.Model):
|
| 332 |
+
name = models.CharField(max_length=30)
|
| 333 |
+
|
| 334 |
+
class Meta:
|
| 335 |
+
abstract = True
|
| 336 |
+
|
| 337 |
+
class ConcreteBase(AbstractBase):
|
| 338 |
+
pass
|
| 339 |
+
|
| 340 |
+
class AbstractDescendant(ConcreteBase):
|
| 341 |
+
class Meta:
|
| 342 |
+
abstract = True
|
| 343 |
+
|
| 344 |
+
class ConcreteDescendant(AbstractDescendant):
|
| 345 |
+
name = models.CharField(max_length=100)
|
| 346 |
+
|
| 347 |
+
self.assertEqual(
|
| 348 |
+
ConcreteDescendant.check(),
|
| 349 |
+
[
|
| 350 |
+
Error(
|
| 351 |
+
"The field 'name' clashes with the field 'name' from "
|
| 352 |
+
"model 'model_inheritance.concretebase'.",
|
| 353 |
+
obj=ConcreteDescendant._meta.get_field("name"),
|
| 354 |
+
id="models.E006",
|
| 355 |
+
)
|
| 356 |
+
],
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
def test_override_one2one_relation_auto_field_clashes(self):
|
| 360 |
+
class ConcreteParent(models.Model):
|
| 361 |
+
name = models.CharField(max_length=255)
|
| 362 |
+
|
| 363 |
+
class AbstractParent(models.Model):
|
| 364 |
+
name = models.IntegerField()
|
| 365 |
+
|
| 366 |
+
class Meta:
|
| 367 |
+
abstract = True
|
| 368 |
+
|
| 369 |
+
msg = (
|
| 370 |
+
"Auto-generated field 'concreteparent_ptr' in class 'Descendant' "
|
| 371 |
+
"for parent_link to base class 'ConcreteParent' clashes with "
|
| 372 |
+
"declared field of the same name."
|
| 373 |
+
)
|
| 374 |
+
with self.assertRaisesMessage(FieldError, msg):
|
| 375 |
+
|
| 376 |
+
class Descendant(ConcreteParent, AbstractParent):
|
| 377 |
+
concreteparent_ptr = models.CharField(max_length=30)
|
| 378 |
+
|
| 379 |
+
def test_abstract_model_with_regular_python_mixin_mro(self):
|
| 380 |
+
class AbstractModel(models.Model):
|
| 381 |
+
name = models.CharField(max_length=255)
|
| 382 |
+
age = models.IntegerField()
|
| 383 |
+
|
| 384 |
+
class Meta:
|
| 385 |
+
abstract = True
|
| 386 |
+
|
| 387 |
+
class Mixin:
|
| 388 |
+
age = None
|
| 389 |
+
|
| 390 |
+
class Mixin2:
|
| 391 |
+
age = 2
|
| 392 |
+
|
| 393 |
+
class DescendantMixin(Mixin):
|
| 394 |
+
pass
|
| 395 |
+
|
| 396 |
+
class ConcreteModel(models.Model):
|
| 397 |
+
foo = models.IntegerField()
|
| 398 |
+
|
| 399 |
+
class ConcreteModel2(ConcreteModel):
|
| 400 |
+
age = models.SmallIntegerField()
|
| 401 |
+
|
| 402 |
+
def fields(model):
|
| 403 |
+
if not hasattr(model, "_meta"):
|
| 404 |
+
return []
|
| 405 |
+
return [(f.name, f.__class__) for f in model._meta.get_fields()]
|
| 406 |
+
|
| 407 |
+
model_dict = {"__module__": "model_inheritance"}
|
| 408 |
+
model1 = type("Model1", (AbstractModel, Mixin), model_dict.copy())
|
| 409 |
+
model2 = type("Model2", (Mixin2, AbstractModel), model_dict.copy())
|
| 410 |
+
model3 = type("Model3", (DescendantMixin, AbstractModel), model_dict.copy())
|
| 411 |
+
model4 = type("Model4", (Mixin2, Mixin, AbstractModel), model_dict.copy())
|
| 412 |
+
model5 = type(
|
| 413 |
+
"Model5", (Mixin2, ConcreteModel2, Mixin, AbstractModel), model_dict.copy()
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
self.assertEqual(
|
| 417 |
+
fields(model1),
|
| 418 |
+
[
|
| 419 |
+
("id", models.AutoField),
|
| 420 |
+
("name", models.CharField),
|
| 421 |
+
("age", models.IntegerField),
|
| 422 |
+
],
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
self.assertEqual(
|
| 426 |
+
fields(model2), [("id", models.AutoField), ("name", models.CharField)]
|
| 427 |
+
)
|
| 428 |
+
self.assertEqual(getattr(model2, "age"), 2)
|
| 429 |
+
|
| 430 |
+
self.assertEqual(
|
| 431 |
+
fields(model3), [("id", models.AutoField), ("name", models.CharField)]
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
self.assertEqual(
|
| 435 |
+
fields(model4), [("id", models.AutoField), ("name", models.CharField)]
|
| 436 |
+
)
|
| 437 |
+
self.assertEqual(getattr(model4, "age"), 2)
|
| 438 |
+
|
| 439 |
+
self.assertEqual(
|
| 440 |
+
fields(model5),
|
| 441 |
+
[
|
| 442 |
+
("id", models.AutoField),
|
| 443 |
+
("foo", models.IntegerField),
|
| 444 |
+
("concretemodel_ptr", models.OneToOneField),
|
| 445 |
+
("age", models.SmallIntegerField),
|
| 446 |
+
("concretemodel2_ptr", models.OneToOneField),
|
| 447 |
+
("name", models.CharField),
|
| 448 |
+
],
|
| 449 |
+
)
|
testbed/django__django/tests/model_inheritance/tests.py
ADDED
|
@@ -0,0 +1,670 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from operator import attrgetter
|
| 2 |
+
|
| 3 |
+
from django.core.exceptions import FieldError, ValidationError
|
| 4 |
+
from django.db import connection, models
|
| 5 |
+
from django.db.models.query_utils import DeferredAttribute
|
| 6 |
+
from django.test import SimpleTestCase, TestCase
|
| 7 |
+
from django.test.utils import CaptureQueriesContext, isolate_apps
|
| 8 |
+
|
| 9 |
+
from .models import (
|
| 10 |
+
Base,
|
| 11 |
+
Chef,
|
| 12 |
+
CommonChild,
|
| 13 |
+
CommonInfo,
|
| 14 |
+
CustomSupplier,
|
| 15 |
+
GrandChild,
|
| 16 |
+
GrandParent,
|
| 17 |
+
ItalianRestaurant,
|
| 18 |
+
ItalianRestaurantCommonParent,
|
| 19 |
+
MixinModel,
|
| 20 |
+
Parent,
|
| 21 |
+
ParkingLot,
|
| 22 |
+
Place,
|
| 23 |
+
Post,
|
| 24 |
+
Restaurant,
|
| 25 |
+
Student,
|
| 26 |
+
SubBase,
|
| 27 |
+
Supplier,
|
| 28 |
+
Title,
|
| 29 |
+
Worker,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class ModelInheritanceTests(TestCase):
|
| 34 |
+
def test_abstract(self):
|
| 35 |
+
# The Student and Worker models both have 'name' and 'age' fields on
|
| 36 |
+
# them and inherit the __str__() method, just as with normal Python
|
| 37 |
+
# subclassing. This is useful if you want to factor out common
|
| 38 |
+
# information for programming purposes, but still completely
|
| 39 |
+
# independent separate models at the database level.
|
| 40 |
+
w1 = Worker.objects.create(name="Fred", age=35, job="Quarry worker")
|
| 41 |
+
Worker.objects.create(name="Barney", age=34, job="Quarry worker")
|
| 42 |
+
|
| 43 |
+
s = Student.objects.create(name="Pebbles", age=5, school_class="1B")
|
| 44 |
+
|
| 45 |
+
self.assertEqual(str(w1), "Worker Fred")
|
| 46 |
+
self.assertEqual(str(s), "Student Pebbles")
|
| 47 |
+
|
| 48 |
+
# The children inherit the Meta class of their parents (if they don't
|
| 49 |
+
# specify their own).
|
| 50 |
+
self.assertSequenceEqual(
|
| 51 |
+
Worker.objects.values("name"),
|
| 52 |
+
[
|
| 53 |
+
{"name": "Barney"},
|
| 54 |
+
{"name": "Fred"},
|
| 55 |
+
],
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Since Student does not subclass CommonInfo's Meta, it has the effect
|
| 59 |
+
# of completely overriding it. So ordering by name doesn't take place
|
| 60 |
+
# for Students.
|
| 61 |
+
self.assertEqual(Student._meta.ordering, [])
|
| 62 |
+
|
| 63 |
+
# However, the CommonInfo class cannot be used as a normal model (it
|
| 64 |
+
# doesn't exist as a model).
|
| 65 |
+
with self.assertRaisesMessage(
|
| 66 |
+
AttributeError, "'CommonInfo' has no attribute 'objects'"
|
| 67 |
+
):
|
| 68 |
+
CommonInfo.objects.all()
|
| 69 |
+
|
| 70 |
+
def test_reverse_relation_for_different_hierarchy_tree(self):
|
| 71 |
+
# Even though p.supplier for a Place 'p' (a parent of a Supplier), a
|
| 72 |
+
# Restaurant object cannot access that reverse relation, since it's not
|
| 73 |
+
# part of the Place-Supplier Hierarchy.
|
| 74 |
+
self.assertSequenceEqual(Place.objects.filter(supplier__name="foo"), [])
|
| 75 |
+
msg = (
|
| 76 |
+
"Cannot resolve keyword 'supplier' into field. Choices are: "
|
| 77 |
+
"address, chef, chef_id, id, italianrestaurant, lot, name, "
|
| 78 |
+
"place_ptr, place_ptr_id, provider, rating, serves_hot_dogs, serves_pizza"
|
| 79 |
+
)
|
| 80 |
+
with self.assertRaisesMessage(FieldError, msg):
|
| 81 |
+
Restaurant.objects.filter(supplier__name="foo")
|
| 82 |
+
|
| 83 |
+
def test_model_with_distinct_accessors(self):
|
| 84 |
+
# The Post model has distinct accessors for the Comment and Link models.
|
| 85 |
+
post = Post.objects.create(title="Lorem Ipsum")
|
| 86 |
+
post.attached_comment_set.create(content="Save $ on V1agr@", is_spam=True)
|
| 87 |
+
post.attached_link_set.create(
|
| 88 |
+
content="The web framework for perfections with deadlines.",
|
| 89 |
+
url="http://www.djangoproject.com/",
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# The Post model doesn't have an attribute called
|
| 93 |
+
# 'attached_%(class)s_set'.
|
| 94 |
+
msg = "'Post' object has no attribute 'attached_%(class)s_set'"
|
| 95 |
+
with self.assertRaisesMessage(AttributeError, msg):
|
| 96 |
+
getattr(post, "attached_%(class)s_set")
|
| 97 |
+
|
| 98 |
+
def test_model_with_distinct_related_query_name(self):
|
| 99 |
+
self.assertSequenceEqual(
|
| 100 |
+
Post.objects.filter(attached_model_inheritance_comments__is_spam=True), []
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
# The Post model doesn't have a related query accessor based on
|
| 104 |
+
# related_name (attached_comment_set).
|
| 105 |
+
msg = "Cannot resolve keyword 'attached_comment_set' into field."
|
| 106 |
+
with self.assertRaisesMessage(FieldError, msg):
|
| 107 |
+
Post.objects.filter(attached_comment_set__is_spam=True)
|
| 108 |
+
|
| 109 |
+
def test_meta_fields_and_ordering(self):
|
| 110 |
+
# Make sure Restaurant and ItalianRestaurant have the right fields in
|
| 111 |
+
# the right order.
|
| 112 |
+
self.assertEqual(
|
| 113 |
+
[f.name for f in Restaurant._meta.fields],
|
| 114 |
+
[
|
| 115 |
+
"id",
|
| 116 |
+
"name",
|
| 117 |
+
"address",
|
| 118 |
+
"place_ptr",
|
| 119 |
+
"rating",
|
| 120 |
+
"serves_hot_dogs",
|
| 121 |
+
"serves_pizza",
|
| 122 |
+
"chef",
|
| 123 |
+
],
|
| 124 |
+
)
|
| 125 |
+
self.assertEqual(
|
| 126 |
+
[f.name for f in ItalianRestaurant._meta.fields],
|
| 127 |
+
[
|
| 128 |
+
"id",
|
| 129 |
+
"name",
|
| 130 |
+
"address",
|
| 131 |
+
"place_ptr",
|
| 132 |
+
"rating",
|
| 133 |
+
"serves_hot_dogs",
|
| 134 |
+
"serves_pizza",
|
| 135 |
+
"chef",
|
| 136 |
+
"restaurant_ptr",
|
| 137 |
+
"serves_gnocchi",
|
| 138 |
+
],
|
| 139 |
+
)
|
| 140 |
+
self.assertEqual(Restaurant._meta.ordering, ["-rating"])
|
| 141 |
+
|
| 142 |
+
def test_custompk_m2m(self):
|
| 143 |
+
b = Base.objects.create()
|
| 144 |
+
b.titles.add(Title.objects.create(title="foof"))
|
| 145 |
+
s = SubBase.objects.create(sub_id=b.id)
|
| 146 |
+
b = Base.objects.get(pk=s.id)
|
| 147 |
+
self.assertNotEqual(b.pk, s.pk)
|
| 148 |
+
# Low-level test for related_val
|
| 149 |
+
self.assertEqual(s.titles.related_val, (s.id,))
|
| 150 |
+
# Higher level test for correct query values (title foof not
|
| 151 |
+
# accidentally found).
|
| 152 |
+
self.assertSequenceEqual(s.titles.all(), [])
|
| 153 |
+
|
| 154 |
+
def test_create_diamond_mti_default_pk(self):
|
| 155 |
+
# 1 INSERT for each base.
|
| 156 |
+
with self.assertNumQueries(4):
|
| 157 |
+
common_child = CommonChild.objects.create()
|
| 158 |
+
# 3 SELECTs for the parents, 1 UPDATE for the child.
|
| 159 |
+
with self.assertNumQueries(4):
|
| 160 |
+
common_child.save()
|
| 161 |
+
|
| 162 |
+
def test_create_diamond_mti_common_parent(self):
|
| 163 |
+
with self.assertNumQueries(4):
|
| 164 |
+
italian_restaurant_child = ItalianRestaurantCommonParent.objects.create(
|
| 165 |
+
name="Ristorante Miron",
|
| 166 |
+
address="1234 W. Ash",
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
self.assertEqual(
|
| 170 |
+
italian_restaurant_child.italianrestaurant_ptr.place_ptr,
|
| 171 |
+
italian_restaurant_child.place_ptr_two,
|
| 172 |
+
)
|
| 173 |
+
self.assertEqual(
|
| 174 |
+
italian_restaurant_child.italianrestaurant_ptr.restaurant_ptr,
|
| 175 |
+
italian_restaurant_child.restaurant_ptr,
|
| 176 |
+
)
|
| 177 |
+
self.assertEqual(
|
| 178 |
+
italian_restaurant_child.restaurant_ptr.place_ptr,
|
| 179 |
+
italian_restaurant_child.place_ptr_two,
|
| 180 |
+
)
|
| 181 |
+
self.assertEqual(italian_restaurant_child.name, "Ristorante Miron")
|
| 182 |
+
self.assertEqual(italian_restaurant_child.address, "1234 W. Ash")
|
| 183 |
+
|
| 184 |
+
def test_update_parent_filtering(self):
|
| 185 |
+
"""
|
| 186 |
+
Updating a field of a model subclass doesn't issue an UPDATE
|
| 187 |
+
query constrained by an inner query (#10399).
|
| 188 |
+
"""
|
| 189 |
+
supplier = Supplier.objects.create(
|
| 190 |
+
name="Central market",
|
| 191 |
+
address="610 some street",
|
| 192 |
+
)
|
| 193 |
+
# Capture the expected query in a database agnostic way
|
| 194 |
+
with CaptureQueriesContext(connection) as captured_queries:
|
| 195 |
+
Place.objects.filter(pk=supplier.pk).update(name=supplier.name)
|
| 196 |
+
expected_sql = captured_queries[0]["sql"]
|
| 197 |
+
# Capture the queries executed when a subclassed model instance is saved.
|
| 198 |
+
with CaptureQueriesContext(connection) as captured_queries:
|
| 199 |
+
supplier.save(update_fields=("name",))
|
| 200 |
+
for query in captured_queries:
|
| 201 |
+
sql = query["sql"]
|
| 202 |
+
if "UPDATE" in sql:
|
| 203 |
+
self.assertEqual(expected_sql, sql)
|
| 204 |
+
|
| 205 |
+
def test_create_child_no_update(self):
|
| 206 |
+
"""Creating a child with non-abstract parents only issues INSERTs."""
|
| 207 |
+
|
| 208 |
+
def a():
|
| 209 |
+
GrandChild.objects.create(
|
| 210 |
+
email="grand_parent@example.com",
|
| 211 |
+
first_name="grand",
|
| 212 |
+
last_name="parent",
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
def b():
|
| 216 |
+
GrandChild().save()
|
| 217 |
+
|
| 218 |
+
for i, test in enumerate([a, b]):
|
| 219 |
+
with self.subTest(i=i), self.assertNumQueries(4), CaptureQueriesContext(
|
| 220 |
+
connection
|
| 221 |
+
) as queries:
|
| 222 |
+
test()
|
| 223 |
+
for query in queries:
|
| 224 |
+
sql = query["sql"]
|
| 225 |
+
self.assertIn("INSERT INTO", sql, sql)
|
| 226 |
+
|
| 227 |
+
def test_create_copy_with_inherited_m2m(self):
|
| 228 |
+
restaurant = Restaurant.objects.create()
|
| 229 |
+
supplier = CustomSupplier.objects.create(
|
| 230 |
+
name="Central market", address="944 W. Fullerton"
|
| 231 |
+
)
|
| 232 |
+
supplier.customers.set([restaurant])
|
| 233 |
+
old_customers = supplier.customers.all()
|
| 234 |
+
supplier.pk = None
|
| 235 |
+
supplier.id = None
|
| 236 |
+
supplier._state.adding = True
|
| 237 |
+
supplier.save()
|
| 238 |
+
supplier.customers.set(old_customers)
|
| 239 |
+
supplier = Supplier.objects.get(pk=supplier.pk)
|
| 240 |
+
self.assertCountEqual(supplier.customers.all(), old_customers)
|
| 241 |
+
self.assertSequenceEqual(supplier.customers.all(), [restaurant])
|
| 242 |
+
|
| 243 |
+
def test_eq(self):
|
| 244 |
+
# Equality doesn't transfer in multitable inheritance.
|
| 245 |
+
self.assertNotEqual(Place(id=1), Restaurant(id=1))
|
| 246 |
+
self.assertNotEqual(Restaurant(id=1), Place(id=1))
|
| 247 |
+
|
| 248 |
+
def test_mixin_init(self):
|
| 249 |
+
m = MixinModel()
|
| 250 |
+
self.assertEqual(m.other_attr, 1)
|
| 251 |
+
|
| 252 |
+
@isolate_apps("model_inheritance")
|
| 253 |
+
def test_abstract_parent_link(self):
|
| 254 |
+
class A(models.Model):
|
| 255 |
+
pass
|
| 256 |
+
|
| 257 |
+
class B(A):
|
| 258 |
+
a = models.OneToOneField("A", parent_link=True, on_delete=models.CASCADE)
|
| 259 |
+
|
| 260 |
+
class Meta:
|
| 261 |
+
abstract = True
|
| 262 |
+
|
| 263 |
+
class C(B):
|
| 264 |
+
pass
|
| 265 |
+
|
| 266 |
+
self.assertIs(C._meta.parents[A], C._meta.get_field("a"))
|
| 267 |
+
|
| 268 |
+
@isolate_apps("model_inheritance")
|
| 269 |
+
def test_init_subclass(self):
|
| 270 |
+
saved_kwargs = {}
|
| 271 |
+
|
| 272 |
+
class A(models.Model):
|
| 273 |
+
def __init_subclass__(cls, **kwargs):
|
| 274 |
+
super().__init_subclass__()
|
| 275 |
+
saved_kwargs.update(kwargs)
|
| 276 |
+
|
| 277 |
+
kwargs = {"x": 1, "y": 2, "z": 3}
|
| 278 |
+
|
| 279 |
+
class B(A, **kwargs):
|
| 280 |
+
pass
|
| 281 |
+
|
| 282 |
+
self.assertEqual(saved_kwargs, kwargs)
|
| 283 |
+
|
| 284 |
+
@isolate_apps("model_inheritance")
|
| 285 |
+
def test_set_name(self):
|
| 286 |
+
class ClassAttr:
|
| 287 |
+
called = None
|
| 288 |
+
|
| 289 |
+
def __set_name__(self_, owner, name):
|
| 290 |
+
self.assertIsNone(self_.called)
|
| 291 |
+
self_.called = (owner, name)
|
| 292 |
+
|
| 293 |
+
class A(models.Model):
|
| 294 |
+
attr = ClassAttr()
|
| 295 |
+
|
| 296 |
+
self.assertEqual(A.attr.called, (A, "attr"))
|
| 297 |
+
|
| 298 |
+
def test_inherited_ordering_pk_desc(self):
|
| 299 |
+
p1 = Parent.objects.create(first_name="Joe", email="joe@email.com")
|
| 300 |
+
p2 = Parent.objects.create(first_name="Jon", email="jon@email.com")
|
| 301 |
+
expected_order_by_sql = "ORDER BY %s.%s DESC" % (
|
| 302 |
+
connection.ops.quote_name(Parent._meta.db_table),
|
| 303 |
+
connection.ops.quote_name(Parent._meta.get_field("grandparent_ptr").column),
|
| 304 |
+
)
|
| 305 |
+
qs = Parent.objects.all()
|
| 306 |
+
self.assertSequenceEqual(qs, [p2, p1])
|
| 307 |
+
self.assertIn(expected_order_by_sql, str(qs.query))
|
| 308 |
+
|
| 309 |
+
def test_queryset_class_getitem(self):
|
| 310 |
+
self.assertIs(models.QuerySet[Post], models.QuerySet)
|
| 311 |
+
self.assertIs(models.QuerySet[Post, Post], models.QuerySet)
|
| 312 |
+
self.assertIs(models.QuerySet[Post, int, str], models.QuerySet)
|
| 313 |
+
|
| 314 |
+
def test_shadow_parent_attribute_with_field(self):
|
| 315 |
+
class ScalarParent(models.Model):
|
| 316 |
+
foo = 1
|
| 317 |
+
|
| 318 |
+
class ScalarOverride(ScalarParent):
|
| 319 |
+
foo = models.IntegerField()
|
| 320 |
+
|
| 321 |
+
self.assertEqual(type(ScalarOverride.foo), DeferredAttribute)
|
| 322 |
+
|
| 323 |
+
def test_shadow_parent_property_with_field(self):
|
| 324 |
+
class PropertyParent(models.Model):
|
| 325 |
+
@property
|
| 326 |
+
def foo(self):
|
| 327 |
+
pass
|
| 328 |
+
|
| 329 |
+
class PropertyOverride(PropertyParent):
|
| 330 |
+
foo = models.IntegerField()
|
| 331 |
+
|
| 332 |
+
self.assertEqual(type(PropertyOverride.foo), DeferredAttribute)
|
| 333 |
+
|
| 334 |
+
def test_shadow_parent_method_with_field(self):
|
| 335 |
+
class MethodParent(models.Model):
|
| 336 |
+
def foo(self):
|
| 337 |
+
pass
|
| 338 |
+
|
| 339 |
+
class MethodOverride(MethodParent):
|
| 340 |
+
foo = models.IntegerField()
|
| 341 |
+
|
| 342 |
+
self.assertEqual(type(MethodOverride.foo), DeferredAttribute)
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class ModelInheritanceDataTests(TestCase):
|
| 346 |
+
@classmethod
|
| 347 |
+
def setUpTestData(cls):
|
| 348 |
+
cls.restaurant = Restaurant.objects.create(
|
| 349 |
+
name="Demon Dogs",
|
| 350 |
+
address="944 W. Fullerton",
|
| 351 |
+
serves_hot_dogs=True,
|
| 352 |
+
serves_pizza=False,
|
| 353 |
+
rating=2,
|
| 354 |
+
)
|
| 355 |
+
|
| 356 |
+
chef = Chef.objects.create(name="Albert")
|
| 357 |
+
cls.italian_restaurant = ItalianRestaurant.objects.create(
|
| 358 |
+
name="Ristorante Miron",
|
| 359 |
+
address="1234 W. Ash",
|
| 360 |
+
serves_hot_dogs=False,
|
| 361 |
+
serves_pizza=False,
|
| 362 |
+
serves_gnocchi=True,
|
| 363 |
+
rating=4,
|
| 364 |
+
chef=chef,
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
def test_filter_inherited_model(self):
|
| 368 |
+
self.assertQuerySetEqual(
|
| 369 |
+
ItalianRestaurant.objects.filter(address="1234 W. Ash"),
|
| 370 |
+
[
|
| 371 |
+
"Ristorante Miron",
|
| 372 |
+
],
|
| 373 |
+
attrgetter("name"),
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
def test_update_inherited_model(self):
|
| 377 |
+
self.italian_restaurant.address = "1234 W. Elm"
|
| 378 |
+
self.italian_restaurant.save()
|
| 379 |
+
self.assertQuerySetEqual(
|
| 380 |
+
ItalianRestaurant.objects.filter(address="1234 W. Elm"),
|
| 381 |
+
[
|
| 382 |
+
"Ristorante Miron",
|
| 383 |
+
],
|
| 384 |
+
attrgetter("name"),
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
def test_parent_fields_available_for_filtering_in_child_model(self):
|
| 388 |
+
# Parent fields can be used directly in filters on the child model.
|
| 389 |
+
self.assertQuerySetEqual(
|
| 390 |
+
Restaurant.objects.filter(name="Demon Dogs"),
|
| 391 |
+
[
|
| 392 |
+
"Demon Dogs",
|
| 393 |
+
],
|
| 394 |
+
attrgetter("name"),
|
| 395 |
+
)
|
| 396 |
+
self.assertQuerySetEqual(
|
| 397 |
+
ItalianRestaurant.objects.filter(address="1234 W. Ash"),
|
| 398 |
+
[
|
| 399 |
+
"Ristorante Miron",
|
| 400 |
+
],
|
| 401 |
+
attrgetter("name"),
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
def test_filter_on_parent_returns_object_of_parent_type(self):
|
| 405 |
+
# Filters against the parent model return objects of the parent's type.
|
| 406 |
+
p = Place.objects.get(name="Demon Dogs")
|
| 407 |
+
self.assertIs(type(p), Place)
|
| 408 |
+
|
| 409 |
+
def test_parent_child_one_to_one_link(self):
|
| 410 |
+
# Since the parent and child are linked by an automatically created
|
| 411 |
+
# OneToOneField, you can get from the parent to the child by using the
|
| 412 |
+
# child's name.
|
| 413 |
+
self.assertEqual(
|
| 414 |
+
Place.objects.get(name="Demon Dogs").restaurant,
|
| 415 |
+
Restaurant.objects.get(name="Demon Dogs"),
|
| 416 |
+
)
|
| 417 |
+
self.assertEqual(
|
| 418 |
+
Place.objects.get(name="Ristorante Miron").restaurant.italianrestaurant,
|
| 419 |
+
ItalianRestaurant.objects.get(name="Ristorante Miron"),
|
| 420 |
+
)
|
| 421 |
+
self.assertEqual(
|
| 422 |
+
Restaurant.objects.get(name="Ristorante Miron").italianrestaurant,
|
| 423 |
+
ItalianRestaurant.objects.get(name="Ristorante Miron"),
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
def test_parent_child_one_to_one_link_on_nonrelated_objects(self):
|
| 427 |
+
# This won't work because the Demon Dogs restaurant is not an Italian
|
| 428 |
+
# restaurant.
|
| 429 |
+
with self.assertRaises(ItalianRestaurant.DoesNotExist):
|
| 430 |
+
Place.objects.get(name="Demon Dogs").restaurant.italianrestaurant
|
| 431 |
+
|
| 432 |
+
def test_inherited_does_not_exist_exception(self):
|
| 433 |
+
# An ItalianRestaurant which does not exist is also a Place which does
|
| 434 |
+
# not exist.
|
| 435 |
+
with self.assertRaises(Place.DoesNotExist):
|
| 436 |
+
ItalianRestaurant.objects.get(name="The Noodle Void")
|
| 437 |
+
|
| 438 |
+
def test_inherited_multiple_objects_returned_exception(self):
|
| 439 |
+
# MultipleObjectsReturned is also inherited.
|
| 440 |
+
with self.assertRaises(Place.MultipleObjectsReturned):
|
| 441 |
+
Restaurant.objects.get()
|
| 442 |
+
|
| 443 |
+
def test_related_objects_for_inherited_models(self):
|
| 444 |
+
# Related objects work just as they normally do.
|
| 445 |
+
s1 = Supplier.objects.create(name="Joe's Chickens", address="123 Sesame St")
|
| 446 |
+
s1.customers.set([self.restaurant, self.italian_restaurant])
|
| 447 |
+
s2 = Supplier.objects.create(name="Luigi's Pasta", address="456 Sesame St")
|
| 448 |
+
s2.customers.set([self.italian_restaurant])
|
| 449 |
+
|
| 450 |
+
# This won't work because the Place we select is not a Restaurant (it's
|
| 451 |
+
# a Supplier).
|
| 452 |
+
p = Place.objects.get(name="Joe's Chickens")
|
| 453 |
+
with self.assertRaises(Restaurant.DoesNotExist):
|
| 454 |
+
p.restaurant
|
| 455 |
+
|
| 456 |
+
self.assertEqual(p.supplier, s1)
|
| 457 |
+
self.assertQuerySetEqual(
|
| 458 |
+
self.italian_restaurant.provider.order_by("-name"),
|
| 459 |
+
["Luigi's Pasta", "Joe's Chickens"],
|
| 460 |
+
attrgetter("name"),
|
| 461 |
+
)
|
| 462 |
+
self.assertQuerySetEqual(
|
| 463 |
+
Restaurant.objects.filter(provider__name__contains="Chickens"),
|
| 464 |
+
[
|
| 465 |
+
"Ristorante Miron",
|
| 466 |
+
"Demon Dogs",
|
| 467 |
+
],
|
| 468 |
+
attrgetter("name"),
|
| 469 |
+
)
|
| 470 |
+
self.assertQuerySetEqual(
|
| 471 |
+
ItalianRestaurant.objects.filter(provider__name__contains="Chickens"),
|
| 472 |
+
[
|
| 473 |
+
"Ristorante Miron",
|
| 474 |
+
],
|
| 475 |
+
attrgetter("name"),
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
ParkingLot.objects.create(name="Main St", address="111 Main St", main_site=s1)
|
| 479 |
+
ParkingLot.objects.create(
|
| 480 |
+
name="Well Lit", address="124 Sesame St", main_site=self.italian_restaurant
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
+
self.assertEqual(
|
| 484 |
+
Restaurant.objects.get(lot__name="Well Lit").name, "Ristorante Miron"
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
def test_update_works_on_parent_and_child_models_at_once(self):
|
| 488 |
+
# The update() command can update fields in parent and child classes at
|
| 489 |
+
# once (although it executed multiple SQL queries to do so).
|
| 490 |
+
rows = Restaurant.objects.filter(
|
| 491 |
+
serves_hot_dogs=True, name__contains="D"
|
| 492 |
+
).update(name="Demon Puppies", serves_hot_dogs=False)
|
| 493 |
+
self.assertEqual(rows, 1)
|
| 494 |
+
|
| 495 |
+
r1 = Restaurant.objects.get(pk=self.restaurant.pk)
|
| 496 |
+
self.assertFalse(r1.serves_hot_dogs)
|
| 497 |
+
self.assertEqual(r1.name, "Demon Puppies")
|
| 498 |
+
|
| 499 |
+
def test_values_works_on_parent_model_fields(self):
|
| 500 |
+
# The values() command also works on fields from parent models.
|
| 501 |
+
self.assertSequenceEqual(
|
| 502 |
+
ItalianRestaurant.objects.values("name", "rating"),
|
| 503 |
+
[
|
| 504 |
+
{"rating": 4, "name": "Ristorante Miron"},
|
| 505 |
+
],
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
def test_select_related_works_on_parent_model_fields(self):
|
| 509 |
+
# select_related works with fields from the parent object as if they
|
| 510 |
+
# were a normal part of the model.
|
| 511 |
+
self.assertNumQueries(2, lambda: ItalianRestaurant.objects.all()[0].chef)
|
| 512 |
+
self.assertNumQueries(
|
| 513 |
+
1, lambda: ItalianRestaurant.objects.select_related("chef")[0].chef
|
| 514 |
+
)
|
| 515 |
+
|
| 516 |
+
def test_select_related_defer(self):
|
| 517 |
+
"""
|
| 518 |
+
#23370 - Should be able to defer child fields when using
|
| 519 |
+
select_related() from parent to child.
|
| 520 |
+
"""
|
| 521 |
+
qs = (
|
| 522 |
+
Restaurant.objects.select_related("italianrestaurant")
|
| 523 |
+
.defer("italianrestaurant__serves_gnocchi")
|
| 524 |
+
.order_by("rating")
|
| 525 |
+
)
|
| 526 |
+
|
| 527 |
+
# The field was actually deferred
|
| 528 |
+
with self.assertNumQueries(2):
|
| 529 |
+
objs = list(qs.all())
|
| 530 |
+
self.assertTrue(objs[1].italianrestaurant.serves_gnocchi)
|
| 531 |
+
|
| 532 |
+
# Model fields where assigned correct values
|
| 533 |
+
self.assertEqual(qs[0].name, "Demon Dogs")
|
| 534 |
+
self.assertEqual(qs[0].rating, 2)
|
| 535 |
+
self.assertEqual(qs[1].italianrestaurant.name, "Ristorante Miron")
|
| 536 |
+
self.assertEqual(qs[1].italianrestaurant.rating, 4)
|
| 537 |
+
|
| 538 |
+
def test_parent_cache_reuse(self):
|
| 539 |
+
place = Place.objects.create()
|
| 540 |
+
GrandChild.objects.create(place=place)
|
| 541 |
+
grand_parent = GrandParent.objects.latest("pk")
|
| 542 |
+
with self.assertNumQueries(1):
|
| 543 |
+
self.assertEqual(grand_parent.place, place)
|
| 544 |
+
parent = grand_parent.parent
|
| 545 |
+
with self.assertNumQueries(0):
|
| 546 |
+
self.assertEqual(parent.place, place)
|
| 547 |
+
child = parent.child
|
| 548 |
+
with self.assertNumQueries(0):
|
| 549 |
+
self.assertEqual(child.place, place)
|
| 550 |
+
grandchild = child.grandchild
|
| 551 |
+
with self.assertNumQueries(0):
|
| 552 |
+
self.assertEqual(grandchild.place, place)
|
| 553 |
+
|
| 554 |
+
def test_update_query_counts(self):
|
| 555 |
+
"""
|
| 556 |
+
Update queries do not generate unnecessary queries (#18304).
|
| 557 |
+
"""
|
| 558 |
+
with self.assertNumQueries(3):
|
| 559 |
+
self.italian_restaurant.save()
|
| 560 |
+
|
| 561 |
+
def test_filter_inherited_on_null(self):
|
| 562 |
+
# Refs #12567
|
| 563 |
+
Supplier.objects.create(
|
| 564 |
+
name="Central market",
|
| 565 |
+
address="610 some street",
|
| 566 |
+
)
|
| 567 |
+
self.assertQuerySetEqual(
|
| 568 |
+
Place.objects.filter(supplier__isnull=False),
|
| 569 |
+
[
|
| 570 |
+
"Central market",
|
| 571 |
+
],
|
| 572 |
+
attrgetter("name"),
|
| 573 |
+
)
|
| 574 |
+
self.assertQuerySetEqual(
|
| 575 |
+
Place.objects.filter(supplier__isnull=True).order_by("name"),
|
| 576 |
+
[
|
| 577 |
+
"Demon Dogs",
|
| 578 |
+
"Ristorante Miron",
|
| 579 |
+
],
|
| 580 |
+
attrgetter("name"),
|
| 581 |
+
)
|
| 582 |
+
|
| 583 |
+
def test_exclude_inherited_on_null(self):
|
| 584 |
+
# Refs #12567
|
| 585 |
+
Supplier.objects.create(
|
| 586 |
+
name="Central market",
|
| 587 |
+
address="610 some street",
|
| 588 |
+
)
|
| 589 |
+
self.assertQuerySetEqual(
|
| 590 |
+
Place.objects.exclude(supplier__isnull=False).order_by("name"),
|
| 591 |
+
[
|
| 592 |
+
"Demon Dogs",
|
| 593 |
+
"Ristorante Miron",
|
| 594 |
+
],
|
| 595 |
+
attrgetter("name"),
|
| 596 |
+
)
|
| 597 |
+
self.assertQuerySetEqual(
|
| 598 |
+
Place.objects.exclude(supplier__isnull=True),
|
| 599 |
+
[
|
| 600 |
+
"Central market",
|
| 601 |
+
],
|
| 602 |
+
attrgetter("name"),
|
| 603 |
+
)
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
@isolate_apps("model_inheritance", "model_inheritance.tests")
|
| 607 |
+
class InheritanceSameModelNameTests(SimpleTestCase):
|
| 608 |
+
def test_abstract_fk_related_name(self):
|
| 609 |
+
related_name = "%(app_label)s_%(class)s_references"
|
| 610 |
+
|
| 611 |
+
class Referenced(models.Model):
|
| 612 |
+
class Meta:
|
| 613 |
+
app_label = "model_inheritance"
|
| 614 |
+
|
| 615 |
+
class AbstractReferent(models.Model):
|
| 616 |
+
reference = models.ForeignKey(
|
| 617 |
+
Referenced, models.CASCADE, related_name=related_name
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
class Meta:
|
| 621 |
+
app_label = "model_inheritance"
|
| 622 |
+
abstract = True
|
| 623 |
+
|
| 624 |
+
class Referent(AbstractReferent):
|
| 625 |
+
class Meta:
|
| 626 |
+
app_label = "model_inheritance"
|
| 627 |
+
|
| 628 |
+
LocalReferent = Referent
|
| 629 |
+
|
| 630 |
+
class Referent(AbstractReferent):
|
| 631 |
+
class Meta:
|
| 632 |
+
app_label = "tests"
|
| 633 |
+
|
| 634 |
+
ForeignReferent = Referent
|
| 635 |
+
|
| 636 |
+
self.assertFalse(hasattr(Referenced, related_name))
|
| 637 |
+
self.assertIs(
|
| 638 |
+
Referenced.model_inheritance_referent_references.field.model, LocalReferent
|
| 639 |
+
)
|
| 640 |
+
self.assertIs(Referenced.tests_referent_references.field.model, ForeignReferent)
|
| 641 |
+
|
| 642 |
+
|
| 643 |
+
class InheritanceUniqueTests(TestCase):
|
| 644 |
+
@classmethod
|
| 645 |
+
def setUpTestData(cls):
|
| 646 |
+
cls.grand_parent = GrandParent.objects.create(
|
| 647 |
+
email="grand_parent@example.com",
|
| 648 |
+
first_name="grand",
|
| 649 |
+
last_name="parent",
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
def test_unique(self):
|
| 653 |
+
grand_child = GrandChild(
|
| 654 |
+
email=self.grand_parent.email,
|
| 655 |
+
first_name="grand",
|
| 656 |
+
last_name="child",
|
| 657 |
+
)
|
| 658 |
+
msg = "Grand parent with this Email already exists."
|
| 659 |
+
with self.assertRaisesMessage(ValidationError, msg):
|
| 660 |
+
grand_child.validate_unique()
|
| 661 |
+
|
| 662 |
+
def test_unique_together(self):
|
| 663 |
+
grand_child = GrandChild(
|
| 664 |
+
email="grand_child@example.com",
|
| 665 |
+
first_name=self.grand_parent.first_name,
|
| 666 |
+
last_name=self.grand_parent.last_name,
|
| 667 |
+
)
|
| 668 |
+
msg = "Grand parent with this First name and Last name already exists."
|
| 669 |
+
with self.assertRaisesMessage(ValidationError, msg):
|
| 670 |
+
grand_child.validate_unique()
|
testbed/django__django/tests/model_inheritance_regress/__init__.py
ADDED
|
File without changes
|
testbed/django__django/tests/model_inheritance_regress/models.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
|
| 3 |
+
from django.db import models
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Place(models.Model):
|
| 7 |
+
name = models.CharField(max_length=50)
|
| 8 |
+
address = models.CharField(max_length=80)
|
| 9 |
+
|
| 10 |
+
class Meta:
|
| 11 |
+
ordering = ("name",)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class Restaurant(Place):
|
| 15 |
+
serves_hot_dogs = models.BooleanField(default=False)
|
| 16 |
+
serves_pizza = models.BooleanField(default=False)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class ItalianRestaurant(Restaurant):
|
| 20 |
+
serves_gnocchi = models.BooleanField(default=False)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class ParkingLot(Place):
|
| 24 |
+
# An explicit link to the parent (we can control the attribute name).
|
| 25 |
+
parent = models.OneToOneField(
|
| 26 |
+
Place, models.CASCADE, primary_key=True, parent_link=True
|
| 27 |
+
)
|
| 28 |
+
capacity = models.IntegerField()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class ParkingLot3(Place):
|
| 32 |
+
# The parent_link connector need not be the pk on the model.
|
| 33 |
+
primary_key = models.AutoField(primary_key=True)
|
| 34 |
+
parent = models.OneToOneField(Place, models.CASCADE, parent_link=True)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class ParkingLot4(models.Model):
|
| 38 |
+
# Test parent_link connector can be discovered in abstract classes.
|
| 39 |
+
parent = models.OneToOneField(Place, models.CASCADE, parent_link=True)
|
| 40 |
+
|
| 41 |
+
class Meta:
|
| 42 |
+
abstract = True
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class ParkingLot4A(ParkingLot4, Place):
|
| 46 |
+
pass
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ParkingLot4B(Place, ParkingLot4):
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class Supplier(models.Model):
|
| 54 |
+
name = models.CharField(max_length=50)
|
| 55 |
+
restaurant = models.ForeignKey(Restaurant, models.CASCADE)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class Wholesaler(Supplier):
|
| 59 |
+
retailer = models.ForeignKey(
|
| 60 |
+
Supplier, models.CASCADE, related_name="wholesale_supplier"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class Parent(models.Model):
|
| 65 |
+
created = models.DateTimeField(default=datetime.datetime.now)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class Child(Parent):
|
| 69 |
+
name = models.CharField(max_length=10)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class SelfRefParent(models.Model):
|
| 73 |
+
parent_data = models.IntegerField()
|
| 74 |
+
self_data = models.ForeignKey("self", models.SET_NULL, null=True)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class SelfRefChild(SelfRefParent):
|
| 78 |
+
child_data = models.IntegerField()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class Article(models.Model):
|
| 82 |
+
headline = models.CharField(max_length=100)
|
| 83 |
+
pub_date = models.DateTimeField()
|
| 84 |
+
|
| 85 |
+
class Meta:
|
| 86 |
+
ordering = ("-pub_date", "headline")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class ArticleWithAuthor(Article):
|
| 90 |
+
author = models.CharField(max_length=100)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class M2MBase(models.Model):
|
| 94 |
+
articles = models.ManyToManyField(Article)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class M2MChild(M2MBase):
|
| 98 |
+
name = models.CharField(max_length=50)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class Evaluation(Article):
|
| 102 |
+
quality = models.IntegerField()
|
| 103 |
+
|
| 104 |
+
class Meta:
|
| 105 |
+
abstract = True
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class QualityControl(Evaluation):
|
| 109 |
+
assignee = models.CharField(max_length=50)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class BaseM(models.Model):
|
| 113 |
+
base_name = models.CharField(max_length=100)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
class DerivedM(BaseM):
|
| 117 |
+
customPK = models.IntegerField(primary_key=True)
|
| 118 |
+
derived_name = models.CharField(max_length=100)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class AuditBase(models.Model):
|
| 122 |
+
planned_date = models.DateField()
|
| 123 |
+
|
| 124 |
+
class Meta:
|
| 125 |
+
abstract = True
|
| 126 |
+
verbose_name_plural = "Audits"
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class CertificationAudit(AuditBase):
|
| 130 |
+
class Meta(AuditBase.Meta):
|
| 131 |
+
abstract = True
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class InternalCertificationAudit(CertificationAudit):
|
| 135 |
+
auditing_dept = models.CharField(max_length=20)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
# Abstract classes don't get m2m tables autocreated.
|
| 139 |
+
class Person(models.Model):
|
| 140 |
+
name = models.CharField(max_length=100)
|
| 141 |
+
|
| 142 |
+
class Meta:
|
| 143 |
+
ordering = ("name",)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class AbstractEvent(models.Model):
|
| 147 |
+
name = models.CharField(max_length=100)
|
| 148 |
+
attendees = models.ManyToManyField(Person, related_name="%(class)s_set")
|
| 149 |
+
|
| 150 |
+
class Meta:
|
| 151 |
+
abstract = True
|
| 152 |
+
ordering = ("name",)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
class BirthdayParty(AbstractEvent):
|
| 156 |
+
pass
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
class BachelorParty(AbstractEvent):
|
| 160 |
+
pass
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
class MessyBachelorParty(BachelorParty):
|
| 164 |
+
pass
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
# Check concrete -> abstract -> concrete inheritance
|
| 168 |
+
class SearchableLocation(models.Model):
|
| 169 |
+
keywords = models.CharField(max_length=255)
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class Station(SearchableLocation):
|
| 173 |
+
name = models.CharField(max_length=128)
|
| 174 |
+
|
| 175 |
+
class Meta:
|
| 176 |
+
abstract = True
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
class BusStation(Station):
|
| 180 |
+
inbound = models.BooleanField(default=False)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class TrainStation(Station):
|
| 184 |
+
zone = models.IntegerField()
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
class User(models.Model):
|
| 188 |
+
username = models.CharField(max_length=30, unique=True)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
class Profile(User):
|
| 192 |
+
profile_id = models.AutoField(primary_key=True)
|
| 193 |
+
extra = models.CharField(max_length=30, blank=True)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
# Check concrete + concrete -> concrete -> concrete
|
| 197 |
+
class Politician(models.Model):
|
| 198 |
+
politician_id = models.AutoField(primary_key=True)
|
| 199 |
+
title = models.CharField(max_length=50)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class Congressman(Person, Politician):
|
| 203 |
+
state = models.CharField(max_length=2)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
class Senator(Congressman):
|
| 207 |
+
pass
|
testbed/django__django/tests/model_inheritance_regress/tests.py
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Regression tests for Model inheritance behavior.
|
| 3 |
+
"""
|
| 4 |
+
import datetime
|
| 5 |
+
from operator import attrgetter
|
| 6 |
+
from unittest import expectedFailure
|
| 7 |
+
|
| 8 |
+
from django import forms
|
| 9 |
+
from django.test import TestCase
|
| 10 |
+
|
| 11 |
+
from .models import (
|
| 12 |
+
ArticleWithAuthor,
|
| 13 |
+
BachelorParty,
|
| 14 |
+
BirthdayParty,
|
| 15 |
+
BusStation,
|
| 16 |
+
Child,
|
| 17 |
+
Congressman,
|
| 18 |
+
DerivedM,
|
| 19 |
+
InternalCertificationAudit,
|
| 20 |
+
ItalianRestaurant,
|
| 21 |
+
M2MChild,
|
| 22 |
+
MessyBachelorParty,
|
| 23 |
+
ParkingLot,
|
| 24 |
+
ParkingLot3,
|
| 25 |
+
ParkingLot4A,
|
| 26 |
+
ParkingLot4B,
|
| 27 |
+
Person,
|
| 28 |
+
Place,
|
| 29 |
+
Politician,
|
| 30 |
+
Profile,
|
| 31 |
+
QualityControl,
|
| 32 |
+
Restaurant,
|
| 33 |
+
SelfRefChild,
|
| 34 |
+
SelfRefParent,
|
| 35 |
+
Senator,
|
| 36 |
+
Supplier,
|
| 37 |
+
TrainStation,
|
| 38 |
+
User,
|
| 39 |
+
Wholesaler,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class ModelInheritanceTest(TestCase):
|
| 44 |
+
def test_model_inheritance(self):
|
| 45 |
+
# Regression for #7350, #7202
|
| 46 |
+
# When you create a Parent object with a specific reference to an
|
| 47 |
+
# existent child instance, saving the Parent doesn't duplicate the
|
| 48 |
+
# child. This behavior is only activated during a raw save - it is
|
| 49 |
+
# mostly relevant to deserialization, but any sort of CORBA style
|
| 50 |
+
# 'narrow()' API would require a similar approach.
|
| 51 |
+
|
| 52 |
+
# Create a child-parent-grandparent chain
|
| 53 |
+
place1 = Place(name="Guido's House of Pasta", address="944 W. Fullerton")
|
| 54 |
+
place1.save_base(raw=True)
|
| 55 |
+
restaurant = Restaurant(
|
| 56 |
+
place_ptr=place1,
|
| 57 |
+
serves_hot_dogs=True,
|
| 58 |
+
serves_pizza=False,
|
| 59 |
+
)
|
| 60 |
+
restaurant.save_base(raw=True)
|
| 61 |
+
italian_restaurant = ItalianRestaurant(
|
| 62 |
+
restaurant_ptr=restaurant, serves_gnocchi=True
|
| 63 |
+
)
|
| 64 |
+
italian_restaurant.save_base(raw=True)
|
| 65 |
+
|
| 66 |
+
# Create a child-parent chain with an explicit parent link
|
| 67 |
+
place2 = Place(name="Main St", address="111 Main St")
|
| 68 |
+
place2.save_base(raw=True)
|
| 69 |
+
park = ParkingLot(parent=place2, capacity=100)
|
| 70 |
+
park.save_base(raw=True)
|
| 71 |
+
|
| 72 |
+
# No extra parent objects have been created.
|
| 73 |
+
places = list(Place.objects.all())
|
| 74 |
+
self.assertEqual(places, [place1, place2])
|
| 75 |
+
|
| 76 |
+
dicts = list(Restaurant.objects.values("name", "serves_hot_dogs"))
|
| 77 |
+
self.assertEqual(
|
| 78 |
+
dicts, [{"name": "Guido's House of Pasta", "serves_hot_dogs": True}]
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
dicts = list(
|
| 82 |
+
ItalianRestaurant.objects.values(
|
| 83 |
+
"name", "serves_hot_dogs", "serves_gnocchi"
|
| 84 |
+
)
|
| 85 |
+
)
|
| 86 |
+
self.assertEqual(
|
| 87 |
+
dicts,
|
| 88 |
+
[
|
| 89 |
+
{
|
| 90 |
+
"name": "Guido's House of Pasta",
|
| 91 |
+
"serves_gnocchi": True,
|
| 92 |
+
"serves_hot_dogs": True,
|
| 93 |
+
}
|
| 94 |
+
],
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
dicts = list(ParkingLot.objects.values("name", "capacity"))
|
| 98 |
+
self.assertEqual(
|
| 99 |
+
dicts,
|
| 100 |
+
[
|
| 101 |
+
{
|
| 102 |
+
"capacity": 100,
|
| 103 |
+
"name": "Main St",
|
| 104 |
+
}
|
| 105 |
+
],
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# You can also update objects when using a raw save.
|
| 109 |
+
place1.name = "Guido's All New House of Pasta"
|
| 110 |
+
place1.save_base(raw=True)
|
| 111 |
+
|
| 112 |
+
restaurant.serves_hot_dogs = False
|
| 113 |
+
restaurant.save_base(raw=True)
|
| 114 |
+
|
| 115 |
+
italian_restaurant.serves_gnocchi = False
|
| 116 |
+
italian_restaurant.save_base(raw=True)
|
| 117 |
+
|
| 118 |
+
place2.name = "Derelict lot"
|
| 119 |
+
place2.save_base(raw=True)
|
| 120 |
+
|
| 121 |
+
park.capacity = 50
|
| 122 |
+
park.save_base(raw=True)
|
| 123 |
+
|
| 124 |
+
# No extra parent objects after an update, either.
|
| 125 |
+
places = list(Place.objects.all())
|
| 126 |
+
self.assertEqual(places, [place2, place1])
|
| 127 |
+
self.assertEqual(places[0].name, "Derelict lot")
|
| 128 |
+
self.assertEqual(places[1].name, "Guido's All New House of Pasta")
|
| 129 |
+
|
| 130 |
+
dicts = list(Restaurant.objects.values("name", "serves_hot_dogs"))
|
| 131 |
+
self.assertEqual(
|
| 132 |
+
dicts,
|
| 133 |
+
[
|
| 134 |
+
{
|
| 135 |
+
"name": "Guido's All New House of Pasta",
|
| 136 |
+
"serves_hot_dogs": False,
|
| 137 |
+
}
|
| 138 |
+
],
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
dicts = list(
|
| 142 |
+
ItalianRestaurant.objects.values(
|
| 143 |
+
"name", "serves_hot_dogs", "serves_gnocchi"
|
| 144 |
+
)
|
| 145 |
+
)
|
| 146 |
+
self.assertEqual(
|
| 147 |
+
dicts,
|
| 148 |
+
[
|
| 149 |
+
{
|
| 150 |
+
"name": "Guido's All New House of Pasta",
|
| 151 |
+
"serves_gnocchi": False,
|
| 152 |
+
"serves_hot_dogs": False,
|
| 153 |
+
}
|
| 154 |
+
],
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
dicts = list(ParkingLot.objects.values("name", "capacity"))
|
| 158 |
+
self.assertEqual(
|
| 159 |
+
dicts,
|
| 160 |
+
[
|
| 161 |
+
{
|
| 162 |
+
"capacity": 50,
|
| 163 |
+
"name": "Derelict lot",
|
| 164 |
+
}
|
| 165 |
+
],
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# If you try to raw_save a parent attribute onto a child object,
|
| 169 |
+
# the attribute will be ignored.
|
| 170 |
+
|
| 171 |
+
italian_restaurant.name = "Lorenzo's Pasta Hut"
|
| 172 |
+
italian_restaurant.save_base(raw=True)
|
| 173 |
+
|
| 174 |
+
# Note that the name has not changed
|
| 175 |
+
# - name is an attribute of Place, not ItalianRestaurant
|
| 176 |
+
dicts = list(
|
| 177 |
+
ItalianRestaurant.objects.values(
|
| 178 |
+
"name", "serves_hot_dogs", "serves_gnocchi"
|
| 179 |
+
)
|
| 180 |
+
)
|
| 181 |
+
self.assertEqual(
|
| 182 |
+
dicts,
|
| 183 |
+
[
|
| 184 |
+
{
|
| 185 |
+
"name": "Guido's All New House of Pasta",
|
| 186 |
+
"serves_gnocchi": False,
|
| 187 |
+
"serves_hot_dogs": False,
|
| 188 |
+
}
|
| 189 |
+
],
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
def test_issue_7105(self):
|
| 193 |
+
# Regressions tests for #7105: dates() queries should be able to use
|
| 194 |
+
# fields from the parent model as easily as the child.
|
| 195 |
+
Child.objects.create(
|
| 196 |
+
name="child", created=datetime.datetime(2008, 6, 26, 17, 0, 0)
|
| 197 |
+
)
|
| 198 |
+
datetimes = list(Child.objects.datetimes("created", "month"))
|
| 199 |
+
self.assertEqual(datetimes, [datetime.datetime(2008, 6, 1, 0, 0)])
|
| 200 |
+
|
| 201 |
+
def test_issue_7276(self):
|
| 202 |
+
# Regression test for #7276: calling delete() on a model with
|
| 203 |
+
# multi-table inheritance should delete the associated rows from any
|
| 204 |
+
# ancestor tables, as well as any descendent objects.
|
| 205 |
+
place1 = Place(name="Guido's House of Pasta", address="944 W. Fullerton")
|
| 206 |
+
place1.save_base(raw=True)
|
| 207 |
+
restaurant = Restaurant(
|
| 208 |
+
place_ptr=place1,
|
| 209 |
+
serves_hot_dogs=True,
|
| 210 |
+
serves_pizza=False,
|
| 211 |
+
)
|
| 212 |
+
restaurant.save_base(raw=True)
|
| 213 |
+
italian_restaurant = ItalianRestaurant(
|
| 214 |
+
restaurant_ptr=restaurant, serves_gnocchi=True
|
| 215 |
+
)
|
| 216 |
+
italian_restaurant.save_base(raw=True)
|
| 217 |
+
|
| 218 |
+
ident = ItalianRestaurant.objects.all()[0].id
|
| 219 |
+
self.assertEqual(Place.objects.get(pk=ident), place1)
|
| 220 |
+
Restaurant.objects.create(
|
| 221 |
+
name="a",
|
| 222 |
+
address="xx",
|
| 223 |
+
serves_hot_dogs=True,
|
| 224 |
+
serves_pizza=False,
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
# This should delete both Restaurants, plus the related places, plus
|
| 228 |
+
# the ItalianRestaurant.
|
| 229 |
+
Restaurant.objects.all().delete()
|
| 230 |
+
|
| 231 |
+
with self.assertRaises(Place.DoesNotExist):
|
| 232 |
+
Place.objects.get(pk=ident)
|
| 233 |
+
with self.assertRaises(ItalianRestaurant.DoesNotExist):
|
| 234 |
+
ItalianRestaurant.objects.get(pk=ident)
|
| 235 |
+
|
| 236 |
+
def test_issue_6755(self):
|
| 237 |
+
"""
|
| 238 |
+
Regression test for #6755
|
| 239 |
+
"""
|
| 240 |
+
r = Restaurant(serves_pizza=False, serves_hot_dogs=False)
|
| 241 |
+
r.save()
|
| 242 |
+
self.assertEqual(r.id, r.place_ptr_id)
|
| 243 |
+
orig_id = r.id
|
| 244 |
+
r = Restaurant(place_ptr_id=orig_id, serves_pizza=True, serves_hot_dogs=False)
|
| 245 |
+
r.save()
|
| 246 |
+
self.assertEqual(r.id, orig_id)
|
| 247 |
+
self.assertEqual(r.id, r.place_ptr_id)
|
| 248 |
+
|
| 249 |
+
def test_issue_11764(self):
|
| 250 |
+
"""
|
| 251 |
+
Regression test for #11764
|
| 252 |
+
"""
|
| 253 |
+
wholesalers = list(Wholesaler.objects.select_related())
|
| 254 |
+
self.assertEqual(wholesalers, [])
|
| 255 |
+
|
| 256 |
+
def test_issue_7853(self):
|
| 257 |
+
"""
|
| 258 |
+
Regression test for #7853
|
| 259 |
+
If the parent class has a self-referential link, make sure that any
|
| 260 |
+
updates to that link via the child update the right table.
|
| 261 |
+
"""
|
| 262 |
+
obj = SelfRefChild.objects.create(child_data=37, parent_data=42)
|
| 263 |
+
obj.delete()
|
| 264 |
+
|
| 265 |
+
def test_get_next_previous_by_date(self):
|
| 266 |
+
"""
|
| 267 |
+
Regression tests for #8076
|
| 268 |
+
get_(next/previous)_by_date should work
|
| 269 |
+
"""
|
| 270 |
+
c1 = ArticleWithAuthor(
|
| 271 |
+
headline="ArticleWithAuthor 1",
|
| 272 |
+
author="Person 1",
|
| 273 |
+
pub_date=datetime.datetime(2005, 8, 1, 3, 0),
|
| 274 |
+
)
|
| 275 |
+
c1.save()
|
| 276 |
+
c2 = ArticleWithAuthor(
|
| 277 |
+
headline="ArticleWithAuthor 2",
|
| 278 |
+
author="Person 2",
|
| 279 |
+
pub_date=datetime.datetime(2005, 8, 1, 10, 0),
|
| 280 |
+
)
|
| 281 |
+
c2.save()
|
| 282 |
+
c3 = ArticleWithAuthor(
|
| 283 |
+
headline="ArticleWithAuthor 3",
|
| 284 |
+
author="Person 3",
|
| 285 |
+
pub_date=datetime.datetime(2005, 8, 2),
|
| 286 |
+
)
|
| 287 |
+
c3.save()
|
| 288 |
+
|
| 289 |
+
self.assertEqual(c1.get_next_by_pub_date(), c2)
|
| 290 |
+
self.assertEqual(c2.get_next_by_pub_date(), c3)
|
| 291 |
+
with self.assertRaises(ArticleWithAuthor.DoesNotExist):
|
| 292 |
+
c3.get_next_by_pub_date()
|
| 293 |
+
self.assertEqual(c3.get_previous_by_pub_date(), c2)
|
| 294 |
+
self.assertEqual(c2.get_previous_by_pub_date(), c1)
|
| 295 |
+
with self.assertRaises(ArticleWithAuthor.DoesNotExist):
|
| 296 |
+
c1.get_previous_by_pub_date()
|
| 297 |
+
|
| 298 |
+
def test_inherited_fields(self):
|
| 299 |
+
"""
|
| 300 |
+
Regression test for #8825 and #9390
|
| 301 |
+
Make sure all inherited fields (esp. m2m fields, in this case) appear
|
| 302 |
+
on the child class.
|
| 303 |
+
"""
|
| 304 |
+
m2mchildren = list(M2MChild.objects.filter(articles__isnull=False))
|
| 305 |
+
self.assertEqual(m2mchildren, [])
|
| 306 |
+
|
| 307 |
+
# Ordering should not include any database column more than once (this
|
| 308 |
+
# is most likely to occur naturally with model inheritance, so we
|
| 309 |
+
# check it here). Regression test for #9390. This necessarily pokes at
|
| 310 |
+
# the SQL string for the query, since the duplicate problems are only
|
| 311 |
+
# apparent at that late stage.
|
| 312 |
+
qs = ArticleWithAuthor.objects.order_by("pub_date", "pk")
|
| 313 |
+
sql = qs.query.get_compiler(qs.db).as_sql()[0]
|
| 314 |
+
fragment = sql[sql.find("ORDER BY") :]
|
| 315 |
+
pos = fragment.find("pub_date")
|
| 316 |
+
self.assertEqual(fragment.find("pub_date", pos + 1), -1)
|
| 317 |
+
|
| 318 |
+
def test_queryset_update_on_parent_model(self):
|
| 319 |
+
"""
|
| 320 |
+
Regression test for #10362
|
| 321 |
+
It is possible to call update() and only change a field in
|
| 322 |
+
an ancestor model.
|
| 323 |
+
"""
|
| 324 |
+
article = ArticleWithAuthor.objects.create(
|
| 325 |
+
author="fred",
|
| 326 |
+
headline="Hey there!",
|
| 327 |
+
pub_date=datetime.datetime(2009, 3, 1, 8, 0, 0),
|
| 328 |
+
)
|
| 329 |
+
update = ArticleWithAuthor.objects.filter(author="fred").update(
|
| 330 |
+
headline="Oh, no!"
|
| 331 |
+
)
|
| 332 |
+
self.assertEqual(update, 1)
|
| 333 |
+
update = ArticleWithAuthor.objects.filter(pk=article.pk).update(
|
| 334 |
+
headline="Oh, no!"
|
| 335 |
+
)
|
| 336 |
+
self.assertEqual(update, 1)
|
| 337 |
+
|
| 338 |
+
derivedm1 = DerivedM.objects.create(
|
| 339 |
+
customPK=44,
|
| 340 |
+
base_name="b1",
|
| 341 |
+
derived_name="d1",
|
| 342 |
+
)
|
| 343 |
+
self.assertEqual(derivedm1.customPK, 44)
|
| 344 |
+
self.assertEqual(derivedm1.base_name, "b1")
|
| 345 |
+
self.assertEqual(derivedm1.derived_name, "d1")
|
| 346 |
+
derivedms = list(DerivedM.objects.all())
|
| 347 |
+
self.assertEqual(derivedms, [derivedm1])
|
| 348 |
+
|
| 349 |
+
def test_use_explicit_o2o_to_parent_as_pk(self):
|
| 350 |
+
"""
|
| 351 |
+
The connector from child to parent need not be the pk on the child.
|
| 352 |
+
"""
|
| 353 |
+
self.assertEqual(ParkingLot3._meta.pk.name, "primary_key")
|
| 354 |
+
# the child->parent link
|
| 355 |
+
self.assertEqual(ParkingLot3._meta.get_ancestor_link(Place).name, "parent")
|
| 356 |
+
|
| 357 |
+
def test_use_explicit_o2o_to_parent_from_abstract_model(self):
|
| 358 |
+
self.assertEqual(ParkingLot4A._meta.pk.name, "parent")
|
| 359 |
+
ParkingLot4A.objects.create(
|
| 360 |
+
name="Parking4A",
|
| 361 |
+
address="21 Jump Street",
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
self.assertEqual(ParkingLot4B._meta.pk.name, "parent")
|
| 365 |
+
ParkingLot4A.objects.create(
|
| 366 |
+
name="Parking4B",
|
| 367 |
+
address="21 Jump Street",
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
def test_all_fields_from_abstract_base_class(self):
|
| 371 |
+
"""
|
| 372 |
+
Regression tests for #7588
|
| 373 |
+
"""
|
| 374 |
+
# All fields from an ABC, including those inherited non-abstractly
|
| 375 |
+
# should be available on child classes (#7588). Creating this instance
|
| 376 |
+
# should work without error.
|
| 377 |
+
QualityControl.objects.create(
|
| 378 |
+
headline="Problems in Django",
|
| 379 |
+
pub_date=datetime.datetime.now(),
|
| 380 |
+
quality=10,
|
| 381 |
+
assignee="adrian",
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
def test_abstract_base_class_m2m_relation_inheritance(self):
|
| 385 |
+
# many-to-many relations defined on an abstract base class are
|
| 386 |
+
# correctly inherited (and created) on the child class.
|
| 387 |
+
p1 = Person.objects.create(name="Alice")
|
| 388 |
+
p2 = Person.objects.create(name="Bob")
|
| 389 |
+
p3 = Person.objects.create(name="Carol")
|
| 390 |
+
p4 = Person.objects.create(name="Dave")
|
| 391 |
+
|
| 392 |
+
birthday = BirthdayParty.objects.create(name="Birthday party for Alice")
|
| 393 |
+
birthday.attendees.set([p1, p3])
|
| 394 |
+
|
| 395 |
+
bachelor = BachelorParty.objects.create(name="Bachelor party for Bob")
|
| 396 |
+
bachelor.attendees.set([p2, p4])
|
| 397 |
+
|
| 398 |
+
parties = list(p1.birthdayparty_set.all())
|
| 399 |
+
self.assertEqual(parties, [birthday])
|
| 400 |
+
|
| 401 |
+
parties = list(p1.bachelorparty_set.all())
|
| 402 |
+
self.assertEqual(parties, [])
|
| 403 |
+
|
| 404 |
+
parties = list(p2.bachelorparty_set.all())
|
| 405 |
+
self.assertEqual(parties, [bachelor])
|
| 406 |
+
|
| 407 |
+
# A subclass of a subclass of an abstract model doesn't get its own
|
| 408 |
+
# accessor.
|
| 409 |
+
self.assertFalse(hasattr(p2, "messybachelorparty_set"))
|
| 410 |
+
|
| 411 |
+
# ... but it does inherit the m2m from its parent
|
| 412 |
+
messy = MessyBachelorParty.objects.create(name="Bachelor party for Dave")
|
| 413 |
+
messy.attendees.set([p4])
|
| 414 |
+
messy_parent = messy.bachelorparty_ptr
|
| 415 |
+
|
| 416 |
+
parties = list(p4.bachelorparty_set.all())
|
| 417 |
+
self.assertEqual(parties, [bachelor, messy_parent])
|
| 418 |
+
|
| 419 |
+
def test_abstract_verbose_name_plural_inheritance(self):
|
| 420 |
+
"""
|
| 421 |
+
verbose_name_plural correctly inherited from ABC if inheritance chain
|
| 422 |
+
includes an abstract model.
|
| 423 |
+
"""
|
| 424 |
+
# Regression test for #11369: verbose_name_plural should be inherited
|
| 425 |
+
# from an ABC even when there are one or more intermediate
|
| 426 |
+
# abstract models in the inheritance chain, for consistency with
|
| 427 |
+
# verbose_name.
|
| 428 |
+
self.assertEqual(InternalCertificationAudit._meta.verbose_name_plural, "Audits")
|
| 429 |
+
|
| 430 |
+
def test_inherited_nullable_exclude(self):
|
| 431 |
+
obj = SelfRefChild.objects.create(child_data=37, parent_data=42)
|
| 432 |
+
self.assertQuerySetEqual(
|
| 433 |
+
SelfRefParent.objects.exclude(self_data=72), [obj.pk], attrgetter("pk")
|
| 434 |
+
)
|
| 435 |
+
self.assertQuerySetEqual(
|
| 436 |
+
SelfRefChild.objects.exclude(self_data=72), [obj.pk], attrgetter("pk")
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
def test_concrete_abstract_concrete_pk(self):
|
| 440 |
+
"""
|
| 441 |
+
Primary key set correctly with concrete->abstract->concrete inheritance.
|
| 442 |
+
"""
|
| 443 |
+
# Regression test for #13987: Primary key is incorrectly determined
|
| 444 |
+
# when more than one model has a concrete->abstract->concrete
|
| 445 |
+
# inheritance hierarchy.
|
| 446 |
+
self.assertEqual(
|
| 447 |
+
len(
|
| 448 |
+
[field for field in BusStation._meta.local_fields if field.primary_key]
|
| 449 |
+
),
|
| 450 |
+
1,
|
| 451 |
+
)
|
| 452 |
+
self.assertEqual(
|
| 453 |
+
len(
|
| 454 |
+
[
|
| 455 |
+
field
|
| 456 |
+
for field in TrainStation._meta.local_fields
|
| 457 |
+
if field.primary_key
|
| 458 |
+
]
|
| 459 |
+
),
|
| 460 |
+
1,
|
| 461 |
+
)
|
| 462 |
+
self.assertIs(BusStation._meta.pk.model, BusStation)
|
| 463 |
+
self.assertIs(TrainStation._meta.pk.model, TrainStation)
|
| 464 |
+
|
| 465 |
+
def test_inherited_unique_field_with_form(self):
|
| 466 |
+
"""
|
| 467 |
+
A model which has different primary key for the parent model passes
|
| 468 |
+
unique field checking correctly (#17615).
|
| 469 |
+
"""
|
| 470 |
+
|
| 471 |
+
class ProfileForm(forms.ModelForm):
|
| 472 |
+
class Meta:
|
| 473 |
+
model = Profile
|
| 474 |
+
fields = "__all__"
|
| 475 |
+
|
| 476 |
+
User.objects.create(username="user_only")
|
| 477 |
+
p = Profile.objects.create(username="user_with_profile")
|
| 478 |
+
form = ProfileForm(
|
| 479 |
+
{"username": "user_with_profile", "extra": "hello"}, instance=p
|
| 480 |
+
)
|
| 481 |
+
self.assertTrue(form.is_valid())
|
| 482 |
+
|
| 483 |
+
def test_inheritance_joins(self):
|
| 484 |
+
# Test for #17502 - check that filtering through two levels of
|
| 485 |
+
# inheritance chain doesn't generate extra joins.
|
| 486 |
+
qs = ItalianRestaurant.objects.all()
|
| 487 |
+
self.assertEqual(str(qs.query).count("JOIN"), 2)
|
| 488 |
+
qs = ItalianRestaurant.objects.filter(name="foo")
|
| 489 |
+
self.assertEqual(str(qs.query).count("JOIN"), 2)
|
| 490 |
+
|
| 491 |
+
@expectedFailure
|
| 492 |
+
def test_inheritance_values_joins(self):
|
| 493 |
+
# It would be nice (but not too important) to skip the middle join in
|
| 494 |
+
# this case. Skipping is possible as nothing from the middle model is
|
| 495 |
+
# used in the qs and top contains direct pointer to the bottom model.
|
| 496 |
+
qs = ItalianRestaurant.objects.values_list("serves_gnocchi").filter(name="foo")
|
| 497 |
+
self.assertEqual(str(qs.query).count("JOIN"), 1)
|
| 498 |
+
|
| 499 |
+
def test_issue_21554(self):
|
| 500 |
+
senator = Senator.objects.create(name="John Doe", title="X", state="Y")
|
| 501 |
+
senator = Senator.objects.get(pk=senator.pk)
|
| 502 |
+
self.assertEqual(senator.name, "John Doe")
|
| 503 |
+
self.assertEqual(senator.title, "X")
|
| 504 |
+
self.assertEqual(senator.state, "Y")
|
| 505 |
+
|
| 506 |
+
def test_inheritance_resolve_columns(self):
|
| 507 |
+
Restaurant.objects.create(
|
| 508 |
+
name="Bobs Cafe",
|
| 509 |
+
address="Somewhere",
|
| 510 |
+
serves_pizza=True,
|
| 511 |
+
serves_hot_dogs=True,
|
| 512 |
+
)
|
| 513 |
+
p = Place.objects.select_related("restaurant")[0]
|
| 514 |
+
self.assertIsInstance(p.restaurant.serves_pizza, bool)
|
| 515 |
+
|
| 516 |
+
def test_inheritance_select_related(self):
|
| 517 |
+
# Regression test for #7246
|
| 518 |
+
r1 = Restaurant.objects.create(
|
| 519 |
+
name="Nobu", serves_hot_dogs=True, serves_pizza=False
|
| 520 |
+
)
|
| 521 |
+
r2 = Restaurant.objects.create(
|
| 522 |
+
name="Craft", serves_hot_dogs=False, serves_pizza=True
|
| 523 |
+
)
|
| 524 |
+
Supplier.objects.create(name="John", restaurant=r1)
|
| 525 |
+
Supplier.objects.create(name="Jane", restaurant=r2)
|
| 526 |
+
|
| 527 |
+
self.assertQuerySetEqual(
|
| 528 |
+
Supplier.objects.order_by("name").select_related(),
|
| 529 |
+
[
|
| 530 |
+
"Jane",
|
| 531 |
+
"John",
|
| 532 |
+
],
|
| 533 |
+
attrgetter("name"),
|
| 534 |
+
)
|
| 535 |
+
|
| 536 |
+
jane = Supplier.objects.order_by("name").select_related("restaurant")[0]
|
| 537 |
+
self.assertEqual(jane.restaurant.name, "Craft")
|
| 538 |
+
|
| 539 |
+
def test_filter_with_parent_fk(self):
|
| 540 |
+
r = Restaurant.objects.create()
|
| 541 |
+
s = Supplier.objects.create(restaurant=r)
|
| 542 |
+
# The mismatch between Restaurant and Place is intentional (#28175).
|
| 543 |
+
self.assertSequenceEqual(
|
| 544 |
+
Supplier.objects.filter(restaurant__in=Place.objects.all()), [s]
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
def test_ptr_accessor_assigns_state(self):
|
| 548 |
+
r = Restaurant.objects.create()
|
| 549 |
+
self.assertIs(r.place_ptr._state.adding, False)
|
| 550 |
+
self.assertEqual(r.place_ptr._state.db, "default")
|
| 551 |
+
|
| 552 |
+
def test_related_filtering_query_efficiency_ticket_15844(self):
|
| 553 |
+
r = Restaurant.objects.create(
|
| 554 |
+
name="Guido's House of Pasta",
|
| 555 |
+
address="944 W. Fullerton",
|
| 556 |
+
serves_hot_dogs=True,
|
| 557 |
+
serves_pizza=False,
|
| 558 |
+
)
|
| 559 |
+
s = Supplier.objects.create(restaurant=r)
|
| 560 |
+
with self.assertNumQueries(1):
|
| 561 |
+
self.assertSequenceEqual(Supplier.objects.filter(restaurant=r), [s])
|
| 562 |
+
with self.assertNumQueries(1):
|
| 563 |
+
self.assertSequenceEqual(r.supplier_set.all(), [s])
|
| 564 |
+
|
| 565 |
+
def test_queries_on_parent_access(self):
|
| 566 |
+
italian_restaurant = ItalianRestaurant.objects.create(
|
| 567 |
+
name="Guido's House of Pasta",
|
| 568 |
+
address="944 W. Fullerton",
|
| 569 |
+
serves_hot_dogs=True,
|
| 570 |
+
serves_pizza=False,
|
| 571 |
+
serves_gnocchi=True,
|
| 572 |
+
)
|
| 573 |
+
|
| 574 |
+
# No queries are made when accessing the parent objects.
|
| 575 |
+
italian_restaurant = ItalianRestaurant.objects.get(pk=italian_restaurant.pk)
|
| 576 |
+
with self.assertNumQueries(0):
|
| 577 |
+
restaurant = italian_restaurant.restaurant_ptr
|
| 578 |
+
self.assertEqual(restaurant.place_ptr.restaurant, restaurant)
|
| 579 |
+
self.assertEqual(restaurant.italianrestaurant, italian_restaurant)
|
| 580 |
+
|
| 581 |
+
# One query is made when accessing the parent objects when the instance
|
| 582 |
+
# is deferred.
|
| 583 |
+
italian_restaurant = ItalianRestaurant.objects.only("serves_gnocchi").get(
|
| 584 |
+
pk=italian_restaurant.pk
|
| 585 |
+
)
|
| 586 |
+
with self.assertNumQueries(1):
|
| 587 |
+
restaurant = italian_restaurant.restaurant_ptr
|
| 588 |
+
self.assertEqual(restaurant.place_ptr.restaurant, restaurant)
|
| 589 |
+
self.assertEqual(restaurant.italianrestaurant, italian_restaurant)
|
| 590 |
+
|
| 591 |
+
# No queries are made when accessing the parent objects when the
|
| 592 |
+
# instance has deferred a field not present in the parent table.
|
| 593 |
+
italian_restaurant = ItalianRestaurant.objects.defer("serves_gnocchi").get(
|
| 594 |
+
pk=italian_restaurant.pk
|
| 595 |
+
)
|
| 596 |
+
with self.assertNumQueries(0):
|
| 597 |
+
restaurant = italian_restaurant.restaurant_ptr
|
| 598 |
+
self.assertEqual(restaurant.place_ptr.restaurant, restaurant)
|
| 599 |
+
self.assertEqual(restaurant.italianrestaurant, italian_restaurant)
|
| 600 |
+
|
| 601 |
+
def test_id_field_update_on_ancestor_change(self):
|
| 602 |
+
place1 = Place.objects.create(name="House of Pasta", address="944 Fullerton")
|
| 603 |
+
place2 = Place.objects.create(name="House of Pizza", address="954 Fullerton")
|
| 604 |
+
place3 = Place.objects.create(name="Burger house", address="964 Fullerton")
|
| 605 |
+
restaurant1 = Restaurant.objects.create(
|
| 606 |
+
place_ptr=place1,
|
| 607 |
+
serves_hot_dogs=True,
|
| 608 |
+
serves_pizza=False,
|
| 609 |
+
)
|
| 610 |
+
restaurant2 = Restaurant.objects.create(
|
| 611 |
+
place_ptr=place2,
|
| 612 |
+
serves_hot_dogs=True,
|
| 613 |
+
serves_pizza=False,
|
| 614 |
+
)
|
| 615 |
+
|
| 616 |
+
italian_restaurant = ItalianRestaurant.objects.create(
|
| 617 |
+
restaurant_ptr=restaurant1,
|
| 618 |
+
serves_gnocchi=True,
|
| 619 |
+
)
|
| 620 |
+
# Changing the parent of a restaurant changes the restaurant's ID & PK.
|
| 621 |
+
restaurant1.place_ptr = place3
|
| 622 |
+
self.assertEqual(restaurant1.pk, place3.pk)
|
| 623 |
+
self.assertEqual(restaurant1.id, place3.id)
|
| 624 |
+
self.assertEqual(restaurant1.pk, restaurant1.id)
|
| 625 |
+
restaurant1.place_ptr = None
|
| 626 |
+
self.assertIsNone(restaurant1.pk)
|
| 627 |
+
self.assertIsNone(restaurant1.id)
|
| 628 |
+
# Changing the parent of an italian restaurant changes the restaurant's
|
| 629 |
+
# ID & PK.
|
| 630 |
+
italian_restaurant.restaurant_ptr = restaurant2
|
| 631 |
+
self.assertEqual(italian_restaurant.pk, restaurant2.pk)
|
| 632 |
+
self.assertEqual(italian_restaurant.id, restaurant2.id)
|
| 633 |
+
self.assertEqual(italian_restaurant.pk, italian_restaurant.id)
|
| 634 |
+
italian_restaurant.restaurant_ptr = None
|
| 635 |
+
self.assertIsNone(italian_restaurant.pk)
|
| 636 |
+
self.assertIsNone(italian_restaurant.id)
|
| 637 |
+
|
| 638 |
+
def test_create_new_instance_with_pk_equals_none(self):
|
| 639 |
+
p1 = Profile.objects.create(username="john")
|
| 640 |
+
p2 = User.objects.get(pk=p1.user_ptr_id).profile
|
| 641 |
+
# Create a new profile by setting pk = None.
|
| 642 |
+
p2.pk = None
|
| 643 |
+
p2.user_ptr_id = None
|
| 644 |
+
p2.username = "bill"
|
| 645 |
+
p2.save()
|
| 646 |
+
self.assertEqual(Profile.objects.count(), 2)
|
| 647 |
+
self.assertEqual(User.objects.get(pk=p1.user_ptr_id).username, "john")
|
| 648 |
+
|
| 649 |
+
def test_create_new_instance_with_pk_equals_none_multi_inheritance(self):
|
| 650 |
+
c1 = Congressman.objects.create(state="PA", name="John", title="senator 1")
|
| 651 |
+
c2 = Person.objects.get(pk=c1.pk).congressman
|
| 652 |
+
# Create a new congressman by setting pk = None.
|
| 653 |
+
c2.pk = None
|
| 654 |
+
c2.id = None
|
| 655 |
+
c2.politician_ptr_id = None
|
| 656 |
+
c2.name = "Bill"
|
| 657 |
+
c2.title = "senator 2"
|
| 658 |
+
c2.save()
|
| 659 |
+
self.assertEqual(Congressman.objects.count(), 2)
|
| 660 |
+
self.assertEqual(Person.objects.get(pk=c1.pk).name, "John")
|
| 661 |
+
self.assertEqual(
|
| 662 |
+
Politician.objects.get(pk=c1.politician_ptr_id).title,
|
| 663 |
+
"senator 1",
|
| 664 |
+
)
|
| 665 |
+
|
| 666 |
+
def test_mti_update_parent_through_child(self):
|
| 667 |
+
Politician.objects.create()
|
| 668 |
+
Congressman.objects.create()
|
| 669 |
+
Congressman.objects.update(title="senator 1")
|
| 670 |
+
self.assertEqual(Congressman.objects.get().title, "senator 1")
|
| 671 |
+
|
| 672 |
+
def test_mti_update_grand_parent_through_child(self):
|
| 673 |
+
Politician.objects.create()
|
| 674 |
+
Senator.objects.create()
|
| 675 |
+
Senator.objects.update(title="senator 1")
|
| 676 |
+
self.assertEqual(Senator.objects.get().title, "senator 1")
|
testbed/django__django/tests/model_meta/__init__.py
ADDED
|
File without changes
|
testbed/django__django/tests/model_meta/models.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
| 2 |
+
from django.contrib.contenttypes.models import ContentType
|
| 3 |
+
from django.db import models
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Relation(models.Model):
|
| 7 |
+
pass
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class InstanceOnlyDescriptor:
|
| 11 |
+
def __get__(self, instance, cls=None):
|
| 12 |
+
if instance is None:
|
| 13 |
+
raise AttributeError("Instance only")
|
| 14 |
+
return 1
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class AbstractPerson(models.Model):
|
| 18 |
+
# DATA fields
|
| 19 |
+
data_abstract = models.CharField(max_length=10)
|
| 20 |
+
fk_abstract = models.ForeignKey(
|
| 21 |
+
Relation, models.CASCADE, related_name="fk_abstract_rel"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# M2M fields
|
| 25 |
+
m2m_abstract = models.ManyToManyField(Relation, related_name="m2m_abstract_rel")
|
| 26 |
+
friends_abstract = models.ManyToManyField("self", symmetrical=True)
|
| 27 |
+
following_abstract = models.ManyToManyField(
|
| 28 |
+
"self", related_name="followers_abstract", symmetrical=False
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# VIRTUAL fields
|
| 32 |
+
data_not_concrete_abstract = models.ForeignObject(
|
| 33 |
+
Relation,
|
| 34 |
+
on_delete=models.CASCADE,
|
| 35 |
+
from_fields=["abstract_non_concrete_id"],
|
| 36 |
+
to_fields=["id"],
|
| 37 |
+
related_name="fo_abstract_rel",
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# GFK fields
|
| 41 |
+
content_type_abstract = models.ForeignKey(
|
| 42 |
+
ContentType, models.CASCADE, related_name="+"
|
| 43 |
+
)
|
| 44 |
+
object_id_abstract = models.PositiveIntegerField()
|
| 45 |
+
content_object_abstract = GenericForeignKey(
|
| 46 |
+
"content_type_abstract", "object_id_abstract"
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# GR fields
|
| 50 |
+
generic_relation_abstract = GenericRelation(Relation)
|
| 51 |
+
|
| 52 |
+
class Meta:
|
| 53 |
+
abstract = True
|
| 54 |
+
|
| 55 |
+
@property
|
| 56 |
+
def test_property(self):
|
| 57 |
+
return 1
|
| 58 |
+
|
| 59 |
+
test_instance_only_descriptor = InstanceOnlyDescriptor()
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class BasePerson(AbstractPerson):
|
| 63 |
+
# DATA fields
|
| 64 |
+
data_base = models.CharField(max_length=10)
|
| 65 |
+
fk_base = models.ForeignKey(Relation, models.CASCADE, related_name="fk_base_rel")
|
| 66 |
+
|
| 67 |
+
# M2M fields
|
| 68 |
+
m2m_base = models.ManyToManyField(Relation, related_name="m2m_base_rel")
|
| 69 |
+
friends_base = models.ManyToManyField("self", symmetrical=True)
|
| 70 |
+
following_base = models.ManyToManyField(
|
| 71 |
+
"self", related_name="followers_base", symmetrical=False
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# VIRTUAL fields
|
| 75 |
+
data_not_concrete_base = models.ForeignObject(
|
| 76 |
+
Relation,
|
| 77 |
+
on_delete=models.CASCADE,
|
| 78 |
+
from_fields=["base_non_concrete_id"],
|
| 79 |
+
to_fields=["id"],
|
| 80 |
+
related_name="fo_base_rel",
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# GFK fields
|
| 84 |
+
content_type_base = models.ForeignKey(ContentType, models.CASCADE, related_name="+")
|
| 85 |
+
object_id_base = models.PositiveIntegerField()
|
| 86 |
+
content_object_base = GenericForeignKey("content_type_base", "object_id_base")
|
| 87 |
+
|
| 88 |
+
# GR fields
|
| 89 |
+
generic_relation_base = GenericRelation(Relation)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class Person(BasePerson):
|
| 93 |
+
# DATA fields
|
| 94 |
+
data_inherited = models.CharField(max_length=10)
|
| 95 |
+
fk_inherited = models.ForeignKey(
|
| 96 |
+
Relation, models.CASCADE, related_name="fk_concrete_rel"
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# M2M Fields
|
| 100 |
+
m2m_inherited = models.ManyToManyField(Relation, related_name="m2m_concrete_rel")
|
| 101 |
+
friends_inherited = models.ManyToManyField("self", symmetrical=True)
|
| 102 |
+
following_inherited = models.ManyToManyField(
|
| 103 |
+
"self", related_name="followers_concrete", symmetrical=False
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# VIRTUAL fields
|
| 107 |
+
data_not_concrete_inherited = models.ForeignObject(
|
| 108 |
+
Relation,
|
| 109 |
+
on_delete=models.CASCADE,
|
| 110 |
+
from_fields=["model_non_concrete_id"],
|
| 111 |
+
to_fields=["id"],
|
| 112 |
+
related_name="fo_concrete_rel",
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# GFK fields
|
| 116 |
+
content_type_concrete = models.ForeignKey(
|
| 117 |
+
ContentType, models.CASCADE, related_name="+"
|
| 118 |
+
)
|
| 119 |
+
object_id_concrete = models.PositiveIntegerField()
|
| 120 |
+
content_object_concrete = GenericForeignKey(
|
| 121 |
+
"content_type_concrete", "object_id_concrete"
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
# GR fields
|
| 125 |
+
generic_relation_concrete = GenericRelation(Relation)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class ProxyPerson(Person):
|
| 129 |
+
class Meta:
|
| 130 |
+
proxy = True
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
class PersonThroughProxySubclass(ProxyPerson):
|
| 134 |
+
pass
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class Relating(models.Model):
|
| 138 |
+
# ForeignKey to BasePerson
|
| 139 |
+
baseperson = models.ForeignKey(
|
| 140 |
+
BasePerson, models.CASCADE, related_name="relating_baseperson"
|
| 141 |
+
)
|
| 142 |
+
baseperson_hidden = models.ForeignKey(BasePerson, models.CASCADE, related_name="+")
|
| 143 |
+
|
| 144 |
+
# ForeignKey to Person
|
| 145 |
+
person = models.ForeignKey(Person, models.CASCADE, related_name="relating_person")
|
| 146 |
+
person_hidden = models.ForeignKey(Person, models.CASCADE, related_name="+")
|
| 147 |
+
|
| 148 |
+
# ForeignKey to ProxyPerson
|
| 149 |
+
proxyperson = models.ForeignKey(
|
| 150 |
+
ProxyPerson, models.CASCADE, related_name="relating_proxyperson"
|
| 151 |
+
)
|
| 152 |
+
proxyperson_hidden = models.ForeignKey(
|
| 153 |
+
ProxyPerson, models.CASCADE, related_name="relating_proxyperson_hidden+"
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
# ManyToManyField to BasePerson
|
| 157 |
+
basepeople = models.ManyToManyField(BasePerson, related_name="relating_basepeople")
|
| 158 |
+
basepeople_hidden = models.ManyToManyField(BasePerson, related_name="+")
|
| 159 |
+
|
| 160 |
+
# ManyToManyField to Person
|
| 161 |
+
people = models.ManyToManyField(Person, related_name="relating_people")
|
| 162 |
+
people_hidden = models.ManyToManyField(Person, related_name="+")
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# ParentListTests models
|
| 166 |
+
class CommonAncestor(models.Model):
|
| 167 |
+
pass
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
class FirstParent(CommonAncestor):
|
| 171 |
+
first_ancestor = models.OneToOneField(
|
| 172 |
+
CommonAncestor, models.CASCADE, primary_key=True, parent_link=True
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class SecondParent(CommonAncestor):
|
| 177 |
+
second_ancestor = models.OneToOneField(
|
| 178 |
+
CommonAncestor, models.CASCADE, primary_key=True, parent_link=True
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
class Child(FirstParent, SecondParent):
|
| 183 |
+
pass
|
testbed/django__django/tests/model_meta/results.py
ADDED
|
@@ -0,0 +1,895 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .models import AbstractPerson, BasePerson, Person, ProxyPerson, Relating, Relation
|
| 2 |
+
|
| 3 |
+
TEST_RESULTS = {
|
| 4 |
+
"get_all_field_names": {
|
| 5 |
+
Person: [
|
| 6 |
+
"baseperson_ptr",
|
| 7 |
+
"baseperson_ptr_id",
|
| 8 |
+
"content_type_abstract",
|
| 9 |
+
"content_type_abstract_id",
|
| 10 |
+
"content_type_base",
|
| 11 |
+
"content_type_base_id",
|
| 12 |
+
"content_type_concrete",
|
| 13 |
+
"content_type_concrete_id",
|
| 14 |
+
"data_abstract",
|
| 15 |
+
"data_base",
|
| 16 |
+
"data_inherited",
|
| 17 |
+
"data_not_concrete_abstract",
|
| 18 |
+
"data_not_concrete_base",
|
| 19 |
+
"data_not_concrete_inherited",
|
| 20 |
+
"fk_abstract",
|
| 21 |
+
"fk_abstract_id",
|
| 22 |
+
"fk_base",
|
| 23 |
+
"fk_base_id",
|
| 24 |
+
"fk_inherited",
|
| 25 |
+
"fk_inherited_id",
|
| 26 |
+
"followers_abstract",
|
| 27 |
+
"followers_base",
|
| 28 |
+
"followers_concrete",
|
| 29 |
+
"following_abstract",
|
| 30 |
+
"following_base",
|
| 31 |
+
"following_inherited",
|
| 32 |
+
"friends_abstract",
|
| 33 |
+
"friends_base",
|
| 34 |
+
"friends_inherited",
|
| 35 |
+
"generic_relation_abstract",
|
| 36 |
+
"generic_relation_base",
|
| 37 |
+
"generic_relation_concrete",
|
| 38 |
+
"id",
|
| 39 |
+
"m2m_abstract",
|
| 40 |
+
"m2m_base",
|
| 41 |
+
"m2m_inherited",
|
| 42 |
+
"object_id_abstract",
|
| 43 |
+
"object_id_base",
|
| 44 |
+
"object_id_concrete",
|
| 45 |
+
"relating_basepeople",
|
| 46 |
+
"relating_baseperson",
|
| 47 |
+
"relating_people",
|
| 48 |
+
"relating_person",
|
| 49 |
+
],
|
| 50 |
+
BasePerson: [
|
| 51 |
+
"content_type_abstract",
|
| 52 |
+
"content_type_abstract_id",
|
| 53 |
+
"content_type_base",
|
| 54 |
+
"content_type_base_id",
|
| 55 |
+
"data_abstract",
|
| 56 |
+
"data_base",
|
| 57 |
+
"data_not_concrete_abstract",
|
| 58 |
+
"data_not_concrete_base",
|
| 59 |
+
"fk_abstract",
|
| 60 |
+
"fk_abstract_id",
|
| 61 |
+
"fk_base",
|
| 62 |
+
"fk_base_id",
|
| 63 |
+
"followers_abstract",
|
| 64 |
+
"followers_base",
|
| 65 |
+
"following_abstract",
|
| 66 |
+
"following_base",
|
| 67 |
+
"friends_abstract",
|
| 68 |
+
"friends_base",
|
| 69 |
+
"generic_relation_abstract",
|
| 70 |
+
"generic_relation_base",
|
| 71 |
+
"id",
|
| 72 |
+
"m2m_abstract",
|
| 73 |
+
"m2m_base",
|
| 74 |
+
"object_id_abstract",
|
| 75 |
+
"object_id_base",
|
| 76 |
+
"person",
|
| 77 |
+
"relating_basepeople",
|
| 78 |
+
"relating_baseperson",
|
| 79 |
+
],
|
| 80 |
+
AbstractPerson: [
|
| 81 |
+
"content_type_abstract",
|
| 82 |
+
"content_type_abstract_id",
|
| 83 |
+
"data_abstract",
|
| 84 |
+
"data_not_concrete_abstract",
|
| 85 |
+
"fk_abstract",
|
| 86 |
+
"fk_abstract_id",
|
| 87 |
+
"following_abstract",
|
| 88 |
+
"friends_abstract",
|
| 89 |
+
"generic_relation_abstract",
|
| 90 |
+
"m2m_abstract",
|
| 91 |
+
"object_id_abstract",
|
| 92 |
+
],
|
| 93 |
+
Relating: [
|
| 94 |
+
"basepeople",
|
| 95 |
+
"basepeople_hidden",
|
| 96 |
+
"baseperson",
|
| 97 |
+
"baseperson_hidden",
|
| 98 |
+
"baseperson_hidden_id",
|
| 99 |
+
"baseperson_id",
|
| 100 |
+
"id",
|
| 101 |
+
"people",
|
| 102 |
+
"people_hidden",
|
| 103 |
+
"person",
|
| 104 |
+
"person_hidden",
|
| 105 |
+
"person_hidden_id",
|
| 106 |
+
"person_id",
|
| 107 |
+
"proxyperson",
|
| 108 |
+
"proxyperson_hidden",
|
| 109 |
+
"proxyperson_hidden_id",
|
| 110 |
+
"proxyperson_id",
|
| 111 |
+
],
|
| 112 |
+
},
|
| 113 |
+
"fields": {
|
| 114 |
+
Person: [
|
| 115 |
+
"id",
|
| 116 |
+
"data_abstract",
|
| 117 |
+
"fk_abstract_id",
|
| 118 |
+
"data_not_concrete_abstract",
|
| 119 |
+
"content_type_abstract_id",
|
| 120 |
+
"object_id_abstract",
|
| 121 |
+
"data_base",
|
| 122 |
+
"fk_base_id",
|
| 123 |
+
"data_not_concrete_base",
|
| 124 |
+
"content_type_base_id",
|
| 125 |
+
"object_id_base",
|
| 126 |
+
"baseperson_ptr_id",
|
| 127 |
+
"data_inherited",
|
| 128 |
+
"fk_inherited_id",
|
| 129 |
+
"data_not_concrete_inherited",
|
| 130 |
+
"content_type_concrete_id",
|
| 131 |
+
"object_id_concrete",
|
| 132 |
+
],
|
| 133 |
+
BasePerson: [
|
| 134 |
+
"id",
|
| 135 |
+
"data_abstract",
|
| 136 |
+
"fk_abstract_id",
|
| 137 |
+
"data_not_concrete_abstract",
|
| 138 |
+
"content_type_abstract_id",
|
| 139 |
+
"object_id_abstract",
|
| 140 |
+
"data_base",
|
| 141 |
+
"fk_base_id",
|
| 142 |
+
"data_not_concrete_base",
|
| 143 |
+
"content_type_base_id",
|
| 144 |
+
"object_id_base",
|
| 145 |
+
],
|
| 146 |
+
AbstractPerson: [
|
| 147 |
+
"data_abstract",
|
| 148 |
+
"fk_abstract_id",
|
| 149 |
+
"data_not_concrete_abstract",
|
| 150 |
+
"content_type_abstract_id",
|
| 151 |
+
"object_id_abstract",
|
| 152 |
+
],
|
| 153 |
+
Relating: [
|
| 154 |
+
"id",
|
| 155 |
+
"baseperson_id",
|
| 156 |
+
"baseperson_hidden_id",
|
| 157 |
+
"person_id",
|
| 158 |
+
"person_hidden_id",
|
| 159 |
+
"proxyperson_id",
|
| 160 |
+
"proxyperson_hidden_id",
|
| 161 |
+
],
|
| 162 |
+
},
|
| 163 |
+
"local_fields": {
|
| 164 |
+
Person: [
|
| 165 |
+
"baseperson_ptr_id",
|
| 166 |
+
"data_inherited",
|
| 167 |
+
"fk_inherited_id",
|
| 168 |
+
"data_not_concrete_inherited",
|
| 169 |
+
"content_type_concrete_id",
|
| 170 |
+
"object_id_concrete",
|
| 171 |
+
],
|
| 172 |
+
BasePerson: [
|
| 173 |
+
"id",
|
| 174 |
+
"data_abstract",
|
| 175 |
+
"fk_abstract_id",
|
| 176 |
+
"data_not_concrete_abstract",
|
| 177 |
+
"content_type_abstract_id",
|
| 178 |
+
"object_id_abstract",
|
| 179 |
+
"data_base",
|
| 180 |
+
"fk_base_id",
|
| 181 |
+
"data_not_concrete_base",
|
| 182 |
+
"content_type_base_id",
|
| 183 |
+
"object_id_base",
|
| 184 |
+
],
|
| 185 |
+
AbstractPerson: [
|
| 186 |
+
"data_abstract",
|
| 187 |
+
"fk_abstract_id",
|
| 188 |
+
"data_not_concrete_abstract",
|
| 189 |
+
"content_type_abstract_id",
|
| 190 |
+
"object_id_abstract",
|
| 191 |
+
],
|
| 192 |
+
Relating: [
|
| 193 |
+
"id",
|
| 194 |
+
"baseperson_id",
|
| 195 |
+
"baseperson_hidden_id",
|
| 196 |
+
"person_id",
|
| 197 |
+
"person_hidden_id",
|
| 198 |
+
"proxyperson_id",
|
| 199 |
+
"proxyperson_hidden_id",
|
| 200 |
+
],
|
| 201 |
+
},
|
| 202 |
+
"local_concrete_fields": {
|
| 203 |
+
Person: [
|
| 204 |
+
"baseperson_ptr_id",
|
| 205 |
+
"data_inherited",
|
| 206 |
+
"fk_inherited_id",
|
| 207 |
+
"content_type_concrete_id",
|
| 208 |
+
"object_id_concrete",
|
| 209 |
+
],
|
| 210 |
+
BasePerson: [
|
| 211 |
+
"id",
|
| 212 |
+
"data_abstract",
|
| 213 |
+
"fk_abstract_id",
|
| 214 |
+
"content_type_abstract_id",
|
| 215 |
+
"object_id_abstract",
|
| 216 |
+
"data_base",
|
| 217 |
+
"fk_base_id",
|
| 218 |
+
"content_type_base_id",
|
| 219 |
+
"object_id_base",
|
| 220 |
+
],
|
| 221 |
+
AbstractPerson: [
|
| 222 |
+
"data_abstract",
|
| 223 |
+
"fk_abstract_id",
|
| 224 |
+
"content_type_abstract_id",
|
| 225 |
+
"object_id_abstract",
|
| 226 |
+
],
|
| 227 |
+
Relating: [
|
| 228 |
+
"id",
|
| 229 |
+
"baseperson_id",
|
| 230 |
+
"baseperson_hidden_id",
|
| 231 |
+
"person_id",
|
| 232 |
+
"person_hidden_id",
|
| 233 |
+
"proxyperson_id",
|
| 234 |
+
"proxyperson_hidden_id",
|
| 235 |
+
],
|
| 236 |
+
},
|
| 237 |
+
"many_to_many": {
|
| 238 |
+
Person: [
|
| 239 |
+
"m2m_abstract",
|
| 240 |
+
"friends_abstract",
|
| 241 |
+
"following_abstract",
|
| 242 |
+
"m2m_base",
|
| 243 |
+
"friends_base",
|
| 244 |
+
"following_base",
|
| 245 |
+
"m2m_inherited",
|
| 246 |
+
"friends_inherited",
|
| 247 |
+
"following_inherited",
|
| 248 |
+
],
|
| 249 |
+
BasePerson: [
|
| 250 |
+
"m2m_abstract",
|
| 251 |
+
"friends_abstract",
|
| 252 |
+
"following_abstract",
|
| 253 |
+
"m2m_base",
|
| 254 |
+
"friends_base",
|
| 255 |
+
"following_base",
|
| 256 |
+
],
|
| 257 |
+
AbstractPerson: [
|
| 258 |
+
"m2m_abstract",
|
| 259 |
+
"friends_abstract",
|
| 260 |
+
"following_abstract",
|
| 261 |
+
],
|
| 262 |
+
Relating: [
|
| 263 |
+
"basepeople",
|
| 264 |
+
"basepeople_hidden",
|
| 265 |
+
"people",
|
| 266 |
+
"people_hidden",
|
| 267 |
+
],
|
| 268 |
+
},
|
| 269 |
+
"many_to_many_with_model": {
|
| 270 |
+
Person: [
|
| 271 |
+
BasePerson,
|
| 272 |
+
BasePerson,
|
| 273 |
+
BasePerson,
|
| 274 |
+
BasePerson,
|
| 275 |
+
BasePerson,
|
| 276 |
+
BasePerson,
|
| 277 |
+
None,
|
| 278 |
+
None,
|
| 279 |
+
None,
|
| 280 |
+
],
|
| 281 |
+
BasePerson: [
|
| 282 |
+
None,
|
| 283 |
+
None,
|
| 284 |
+
None,
|
| 285 |
+
None,
|
| 286 |
+
None,
|
| 287 |
+
None,
|
| 288 |
+
],
|
| 289 |
+
AbstractPerson: [
|
| 290 |
+
None,
|
| 291 |
+
None,
|
| 292 |
+
None,
|
| 293 |
+
],
|
| 294 |
+
Relating: [
|
| 295 |
+
None,
|
| 296 |
+
None,
|
| 297 |
+
None,
|
| 298 |
+
None,
|
| 299 |
+
],
|
| 300 |
+
},
|
| 301 |
+
"get_all_related_objects_with_model_legacy": {
|
| 302 |
+
Person: (
|
| 303 |
+
("relating_baseperson", BasePerson),
|
| 304 |
+
("relating_person", None),
|
| 305 |
+
),
|
| 306 |
+
BasePerson: (
|
| 307 |
+
("person", None),
|
| 308 |
+
("relating_baseperson", None),
|
| 309 |
+
),
|
| 310 |
+
Relation: (
|
| 311 |
+
("fk_abstract_rel", None),
|
| 312 |
+
("fo_abstract_rel", None),
|
| 313 |
+
("fk_base_rel", None),
|
| 314 |
+
("fo_base_rel", None),
|
| 315 |
+
("fk_concrete_rel", None),
|
| 316 |
+
("fo_concrete_rel", None),
|
| 317 |
+
),
|
| 318 |
+
},
|
| 319 |
+
"get_all_related_objects_with_model_hidden_local": {
|
| 320 |
+
Person: (
|
| 321 |
+
("+", None),
|
| 322 |
+
("_model_meta_relating_people_hidden_+", None),
|
| 323 |
+
("Person_following_inherited+", None),
|
| 324 |
+
("Person_following_inherited+", None),
|
| 325 |
+
("Person_friends_inherited+", None),
|
| 326 |
+
("Person_friends_inherited+", None),
|
| 327 |
+
("Person_m2m_inherited+", None),
|
| 328 |
+
("Relating_people+", None),
|
| 329 |
+
("Relating_people_hidden+", None),
|
| 330 |
+
("followers_concrete", None),
|
| 331 |
+
("friends_inherited_rel_+", None),
|
| 332 |
+
("personthroughproxysubclass", None),
|
| 333 |
+
("relating_people", None),
|
| 334 |
+
("relating_person", None),
|
| 335 |
+
("relating_proxyperson", None),
|
| 336 |
+
("relating_proxyperson_hidden+", None),
|
| 337 |
+
),
|
| 338 |
+
ProxyPerson: (
|
| 339 |
+
("+", Person),
|
| 340 |
+
("_model_meta_relating_people_hidden_+", Person),
|
| 341 |
+
("Person_following_inherited+", Person),
|
| 342 |
+
("Person_following_inherited+", Person),
|
| 343 |
+
("Person_friends_inherited+", Person),
|
| 344 |
+
("Person_friends_inherited+", Person),
|
| 345 |
+
("Person_m2m_inherited+", Person),
|
| 346 |
+
("Relating_people+", Person),
|
| 347 |
+
("Relating_people_hidden+", Person),
|
| 348 |
+
("followers_concrete", Person),
|
| 349 |
+
("friends_inherited_rel_+", Person),
|
| 350 |
+
("personthroughproxysubclass", Person),
|
| 351 |
+
("relating_people", Person),
|
| 352 |
+
("relating_person", Person),
|
| 353 |
+
("relating_proxyperson", Person),
|
| 354 |
+
("relating_proxyperson_hidden+", Person),
|
| 355 |
+
),
|
| 356 |
+
BasePerson: (
|
| 357 |
+
("+", None),
|
| 358 |
+
("_model_meta_relating_basepeople_hidden_+", None),
|
| 359 |
+
("BasePerson_following_abstract+", None),
|
| 360 |
+
("BasePerson_following_abstract+", None),
|
| 361 |
+
("BasePerson_following_base+", None),
|
| 362 |
+
("BasePerson_following_base+", None),
|
| 363 |
+
("BasePerson_friends_abstract+", None),
|
| 364 |
+
("BasePerson_friends_abstract+", None),
|
| 365 |
+
("BasePerson_friends_base+", None),
|
| 366 |
+
("BasePerson_friends_base+", None),
|
| 367 |
+
("BasePerson_m2m_abstract+", None),
|
| 368 |
+
("BasePerson_m2m_base+", None),
|
| 369 |
+
("Relating_basepeople+", None),
|
| 370 |
+
("Relating_basepeople_hidden+", None),
|
| 371 |
+
("followers_abstract", None),
|
| 372 |
+
("followers_base", None),
|
| 373 |
+
("friends_abstract_rel_+", None),
|
| 374 |
+
("friends_base_rel_+", None),
|
| 375 |
+
("person", None),
|
| 376 |
+
("relating_basepeople", None),
|
| 377 |
+
("relating_baseperson", None),
|
| 378 |
+
),
|
| 379 |
+
Relation: (
|
| 380 |
+
("+", None),
|
| 381 |
+
("+", None),
|
| 382 |
+
("+", None),
|
| 383 |
+
("+", None),
|
| 384 |
+
("+", None),
|
| 385 |
+
("+", None),
|
| 386 |
+
("+", None),
|
| 387 |
+
("+", None),
|
| 388 |
+
("+", None),
|
| 389 |
+
("+", None),
|
| 390 |
+
("+", None),
|
| 391 |
+
("BasePerson_m2m_abstract+", None),
|
| 392 |
+
("BasePerson_m2m_base+", None),
|
| 393 |
+
("Person_m2m_inherited+", None),
|
| 394 |
+
("fk_abstract_rel", None),
|
| 395 |
+
("fk_base_rel", None),
|
| 396 |
+
("fk_concrete_rel", None),
|
| 397 |
+
("fo_abstract_rel", None),
|
| 398 |
+
("fo_base_rel", None),
|
| 399 |
+
("fo_concrete_rel", None),
|
| 400 |
+
("m2m_abstract_rel", None),
|
| 401 |
+
("m2m_base_rel", None),
|
| 402 |
+
("m2m_concrete_rel", None),
|
| 403 |
+
),
|
| 404 |
+
},
|
| 405 |
+
"get_all_related_objects_with_model_hidden": {
|
| 406 |
+
Person: (
|
| 407 |
+
("+", BasePerson),
|
| 408 |
+
("+", None),
|
| 409 |
+
("_model_meta_relating_basepeople_hidden_+", BasePerson),
|
| 410 |
+
("_model_meta_relating_people_hidden_+", None),
|
| 411 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 412 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 413 |
+
("BasePerson_following_base+", BasePerson),
|
| 414 |
+
("BasePerson_following_base+", BasePerson),
|
| 415 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 416 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 417 |
+
("BasePerson_friends_base+", BasePerson),
|
| 418 |
+
("BasePerson_friends_base+", BasePerson),
|
| 419 |
+
("BasePerson_m2m_abstract+", BasePerson),
|
| 420 |
+
("BasePerson_m2m_base+", BasePerson),
|
| 421 |
+
("Person_following_inherited+", None),
|
| 422 |
+
("Person_following_inherited+", None),
|
| 423 |
+
("Person_friends_inherited+", None),
|
| 424 |
+
("Person_friends_inherited+", None),
|
| 425 |
+
("Person_m2m_inherited+", None),
|
| 426 |
+
("Relating_basepeople+", BasePerson),
|
| 427 |
+
("Relating_basepeople_hidden+", BasePerson),
|
| 428 |
+
("Relating_people+", None),
|
| 429 |
+
("Relating_people_hidden+", None),
|
| 430 |
+
("followers_abstract", BasePerson),
|
| 431 |
+
("followers_base", BasePerson),
|
| 432 |
+
("followers_concrete", None),
|
| 433 |
+
("friends_abstract_rel_+", BasePerson),
|
| 434 |
+
("friends_base_rel_+", BasePerson),
|
| 435 |
+
("friends_inherited_rel_+", None),
|
| 436 |
+
("personthroughproxysubclass", None),
|
| 437 |
+
("relating_basepeople", BasePerson),
|
| 438 |
+
("relating_baseperson", BasePerson),
|
| 439 |
+
("relating_people", None),
|
| 440 |
+
("relating_person", None),
|
| 441 |
+
("relating_proxyperson", None),
|
| 442 |
+
("relating_proxyperson_hidden+", None),
|
| 443 |
+
),
|
| 444 |
+
ProxyPerson: (
|
| 445 |
+
("+", BasePerson),
|
| 446 |
+
("+", Person),
|
| 447 |
+
("_model_meta_relating_basepeople_hidden_+", BasePerson),
|
| 448 |
+
("_model_meta_relating_people_hidden_+", Person),
|
| 449 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 450 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 451 |
+
("BasePerson_following_base+", BasePerson),
|
| 452 |
+
("BasePerson_following_base+", BasePerson),
|
| 453 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 454 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 455 |
+
("BasePerson_friends_base+", BasePerson),
|
| 456 |
+
("BasePerson_friends_base+", BasePerson),
|
| 457 |
+
("BasePerson_m2m_abstract+", BasePerson),
|
| 458 |
+
("BasePerson_m2m_base+", BasePerson),
|
| 459 |
+
("Person_following_inherited+", Person),
|
| 460 |
+
("Person_following_inherited+", Person),
|
| 461 |
+
("Person_friends_inherited+", Person),
|
| 462 |
+
("Person_friends_inherited+", Person),
|
| 463 |
+
("Person_m2m_inherited+", Person),
|
| 464 |
+
("Relating_basepeople+", BasePerson),
|
| 465 |
+
("Relating_basepeople_hidden+", BasePerson),
|
| 466 |
+
("Relating_people+", Person),
|
| 467 |
+
("Relating_people_hidden+", Person),
|
| 468 |
+
("followers_abstract", BasePerson),
|
| 469 |
+
("followers_base", BasePerson),
|
| 470 |
+
("followers_concrete", Person),
|
| 471 |
+
("friends_abstract_rel_+", BasePerson),
|
| 472 |
+
("friends_base_rel_+", BasePerson),
|
| 473 |
+
("friends_inherited_rel_+", Person),
|
| 474 |
+
("personthroughproxysubclass", Person),
|
| 475 |
+
("relating_basepeople", BasePerson),
|
| 476 |
+
("relating_baseperson", BasePerson),
|
| 477 |
+
("relating_people", Person),
|
| 478 |
+
("relating_person", Person),
|
| 479 |
+
("relating_proxyperson", Person),
|
| 480 |
+
("relating_proxyperson_hidden+", Person),
|
| 481 |
+
),
|
| 482 |
+
BasePerson: (
|
| 483 |
+
("+", None),
|
| 484 |
+
("_model_meta_relating_basepeople_hidden_+", None),
|
| 485 |
+
("BasePerson_following_abstract+", None),
|
| 486 |
+
("BasePerson_following_abstract+", None),
|
| 487 |
+
("BasePerson_following_base+", None),
|
| 488 |
+
("BasePerson_following_base+", None),
|
| 489 |
+
("BasePerson_friends_abstract+", None),
|
| 490 |
+
("BasePerson_friends_abstract+", None),
|
| 491 |
+
("BasePerson_friends_base+", None),
|
| 492 |
+
("BasePerson_friends_base+", None),
|
| 493 |
+
("BasePerson_m2m_abstract+", None),
|
| 494 |
+
("BasePerson_m2m_base+", None),
|
| 495 |
+
("Relating_basepeople+", None),
|
| 496 |
+
("Relating_basepeople_hidden+", None),
|
| 497 |
+
("followers_abstract", None),
|
| 498 |
+
("followers_base", None),
|
| 499 |
+
("friends_abstract_rel_+", None),
|
| 500 |
+
("friends_base_rel_+", None),
|
| 501 |
+
("person", None),
|
| 502 |
+
("relating_basepeople", None),
|
| 503 |
+
("relating_baseperson", None),
|
| 504 |
+
),
|
| 505 |
+
Relation: (
|
| 506 |
+
("+", None),
|
| 507 |
+
("+", None),
|
| 508 |
+
("+", None),
|
| 509 |
+
("+", None),
|
| 510 |
+
("+", None),
|
| 511 |
+
("+", None),
|
| 512 |
+
("+", None),
|
| 513 |
+
("+", None),
|
| 514 |
+
("+", None),
|
| 515 |
+
("+", None),
|
| 516 |
+
("+", None),
|
| 517 |
+
("BasePerson_m2m_abstract+", None),
|
| 518 |
+
("BasePerson_m2m_base+", None),
|
| 519 |
+
("Person_m2m_inherited+", None),
|
| 520 |
+
("fk_abstract_rel", None),
|
| 521 |
+
("fk_base_rel", None),
|
| 522 |
+
("fk_concrete_rel", None),
|
| 523 |
+
("fo_abstract_rel", None),
|
| 524 |
+
("fo_base_rel", None),
|
| 525 |
+
("fo_concrete_rel", None),
|
| 526 |
+
("m2m_abstract_rel", None),
|
| 527 |
+
("m2m_base_rel", None),
|
| 528 |
+
("m2m_concrete_rel", None),
|
| 529 |
+
),
|
| 530 |
+
},
|
| 531 |
+
"get_all_related_objects_with_model_local": {
|
| 532 |
+
Person: (
|
| 533 |
+
("followers_concrete", None),
|
| 534 |
+
("personthroughproxysubclass", None),
|
| 535 |
+
("relating_person", None),
|
| 536 |
+
("relating_people", None),
|
| 537 |
+
("relating_proxyperson", None),
|
| 538 |
+
),
|
| 539 |
+
ProxyPerson: (
|
| 540 |
+
("followers_concrete", Person),
|
| 541 |
+
("personthroughproxysubclass", Person),
|
| 542 |
+
("relating_person", Person),
|
| 543 |
+
("relating_people", Person),
|
| 544 |
+
("relating_proxyperson", Person),
|
| 545 |
+
),
|
| 546 |
+
BasePerson: (
|
| 547 |
+
("followers_abstract", None),
|
| 548 |
+
("followers_base", None),
|
| 549 |
+
("person", None),
|
| 550 |
+
("relating_baseperson", None),
|
| 551 |
+
("relating_basepeople", None),
|
| 552 |
+
),
|
| 553 |
+
Relation: (
|
| 554 |
+
("fk_abstract_rel", None),
|
| 555 |
+
("fo_abstract_rel", None),
|
| 556 |
+
("fk_base_rel", None),
|
| 557 |
+
("fo_base_rel", None),
|
| 558 |
+
("m2m_abstract_rel", None),
|
| 559 |
+
("m2m_base_rel", None),
|
| 560 |
+
("fk_concrete_rel", None),
|
| 561 |
+
("fo_concrete_rel", None),
|
| 562 |
+
("m2m_concrete_rel", None),
|
| 563 |
+
),
|
| 564 |
+
},
|
| 565 |
+
"get_all_related_objects_with_model": {
|
| 566 |
+
Person: (
|
| 567 |
+
("followers_abstract", BasePerson),
|
| 568 |
+
("followers_base", BasePerson),
|
| 569 |
+
("relating_baseperson", BasePerson),
|
| 570 |
+
("relating_basepeople", BasePerson),
|
| 571 |
+
("followers_concrete", None),
|
| 572 |
+
("personthroughproxysubclass", None),
|
| 573 |
+
("relating_person", None),
|
| 574 |
+
("relating_people", None),
|
| 575 |
+
("relating_proxyperson", None),
|
| 576 |
+
),
|
| 577 |
+
ProxyPerson: (
|
| 578 |
+
("followers_abstract", BasePerson),
|
| 579 |
+
("followers_base", BasePerson),
|
| 580 |
+
("relating_baseperson", BasePerson),
|
| 581 |
+
("relating_basepeople", BasePerson),
|
| 582 |
+
("followers_concrete", Person),
|
| 583 |
+
("personthroughproxysubclass", Person),
|
| 584 |
+
("relating_person", Person),
|
| 585 |
+
("relating_people", Person),
|
| 586 |
+
("relating_proxyperson", Person),
|
| 587 |
+
),
|
| 588 |
+
BasePerson: (
|
| 589 |
+
("followers_abstract", None),
|
| 590 |
+
("followers_base", None),
|
| 591 |
+
("person", None),
|
| 592 |
+
("relating_baseperson", None),
|
| 593 |
+
("relating_basepeople", None),
|
| 594 |
+
),
|
| 595 |
+
Relation: (
|
| 596 |
+
("fk_abstract_rel", None),
|
| 597 |
+
("fo_abstract_rel", None),
|
| 598 |
+
("fk_base_rel", None),
|
| 599 |
+
("fo_base_rel", None),
|
| 600 |
+
("m2m_abstract_rel", None),
|
| 601 |
+
("m2m_base_rel", None),
|
| 602 |
+
("fk_concrete_rel", None),
|
| 603 |
+
("fo_concrete_rel", None),
|
| 604 |
+
("m2m_concrete_rel", None),
|
| 605 |
+
),
|
| 606 |
+
},
|
| 607 |
+
"get_all_related_objects_with_model_local_legacy": {
|
| 608 |
+
Person: (("relating_person", None),),
|
| 609 |
+
BasePerson: (("person", None), ("relating_baseperson", None)),
|
| 610 |
+
Relation: (
|
| 611 |
+
("fk_abstract_rel", None),
|
| 612 |
+
("fo_abstract_rel", None),
|
| 613 |
+
("fk_base_rel", None),
|
| 614 |
+
("fo_base_rel", None),
|
| 615 |
+
("fk_concrete_rel", None),
|
| 616 |
+
("fo_concrete_rel", None),
|
| 617 |
+
),
|
| 618 |
+
},
|
| 619 |
+
"get_all_related_objects_with_model_hidden_legacy": {
|
| 620 |
+
BasePerson: (
|
| 621 |
+
("+", None),
|
| 622 |
+
("BasePerson_following_abstract+", None),
|
| 623 |
+
("BasePerson_following_abstract+", None),
|
| 624 |
+
("BasePerson_following_base+", None),
|
| 625 |
+
("BasePerson_following_base+", None),
|
| 626 |
+
("BasePerson_friends_abstract+", None),
|
| 627 |
+
("BasePerson_friends_abstract+", None),
|
| 628 |
+
("BasePerson_friends_base+", None),
|
| 629 |
+
("BasePerson_friends_base+", None),
|
| 630 |
+
("BasePerson_m2m_abstract+", None),
|
| 631 |
+
("BasePerson_m2m_base+", None),
|
| 632 |
+
("Relating_basepeople+", None),
|
| 633 |
+
("Relating_basepeople_hidden+", None),
|
| 634 |
+
("person", None),
|
| 635 |
+
("relating_baseperson", None),
|
| 636 |
+
),
|
| 637 |
+
Person: (
|
| 638 |
+
("+", BasePerson),
|
| 639 |
+
("+", None),
|
| 640 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 641 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 642 |
+
("BasePerson_following_base+", BasePerson),
|
| 643 |
+
("BasePerson_following_base+", BasePerson),
|
| 644 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 645 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 646 |
+
("BasePerson_friends_base+", BasePerson),
|
| 647 |
+
("BasePerson_friends_base+", BasePerson),
|
| 648 |
+
("BasePerson_m2m_abstract+", BasePerson),
|
| 649 |
+
("BasePerson_m2m_base+", BasePerson),
|
| 650 |
+
("Person_following_inherited+", None),
|
| 651 |
+
("Person_following_inherited+", None),
|
| 652 |
+
("Person_friends_inherited+", None),
|
| 653 |
+
("Person_friends_inherited+", None),
|
| 654 |
+
("Person_m2m_inherited+", None),
|
| 655 |
+
("Relating_basepeople+", BasePerson),
|
| 656 |
+
("Relating_basepeople_hidden+", BasePerson),
|
| 657 |
+
("Relating_people+", None),
|
| 658 |
+
("Relating_people_hidden+", None),
|
| 659 |
+
("relating_baseperson", BasePerson),
|
| 660 |
+
("relating_person", None),
|
| 661 |
+
),
|
| 662 |
+
Relation: (
|
| 663 |
+
("+", None),
|
| 664 |
+
("+", None),
|
| 665 |
+
("+", None),
|
| 666 |
+
("+", None),
|
| 667 |
+
("+", None),
|
| 668 |
+
("+", None),
|
| 669 |
+
("+", None),
|
| 670 |
+
("+", None),
|
| 671 |
+
("BasePerson_m2m_abstract+", None),
|
| 672 |
+
("BasePerson_m2m_base+", None),
|
| 673 |
+
("Person_m2m_inherited+", None),
|
| 674 |
+
("fk_abstract_rel", None),
|
| 675 |
+
("fk_base_rel", None),
|
| 676 |
+
("fk_concrete_rel", None),
|
| 677 |
+
("fo_abstract_rel", None),
|
| 678 |
+
("fo_base_rel", None),
|
| 679 |
+
("fo_concrete_rel", None),
|
| 680 |
+
),
|
| 681 |
+
},
|
| 682 |
+
"get_all_related_objects_with_model_hidden_local_legacy": {
|
| 683 |
+
BasePerson: (
|
| 684 |
+
("+", None),
|
| 685 |
+
("BasePerson_following_abstract+", None),
|
| 686 |
+
("BasePerson_following_abstract+", None),
|
| 687 |
+
("BasePerson_following_base+", None),
|
| 688 |
+
("BasePerson_following_base+", None),
|
| 689 |
+
("BasePerson_friends_abstract+", None),
|
| 690 |
+
("BasePerson_friends_abstract+", None),
|
| 691 |
+
("BasePerson_friends_base+", None),
|
| 692 |
+
("BasePerson_friends_base+", None),
|
| 693 |
+
("BasePerson_m2m_abstract+", None),
|
| 694 |
+
("BasePerson_m2m_base+", None),
|
| 695 |
+
("Relating_basepeople+", None),
|
| 696 |
+
("Relating_basepeople_hidden+", None),
|
| 697 |
+
("person", None),
|
| 698 |
+
("relating_baseperson", None),
|
| 699 |
+
),
|
| 700 |
+
Person: (
|
| 701 |
+
("+", None),
|
| 702 |
+
("Person_following_inherited+", None),
|
| 703 |
+
("Person_following_inherited+", None),
|
| 704 |
+
("Person_friends_inherited+", None),
|
| 705 |
+
("Person_friends_inherited+", None),
|
| 706 |
+
("Person_m2m_inherited+", None),
|
| 707 |
+
("Relating_people+", None),
|
| 708 |
+
("Relating_people_hidden+", None),
|
| 709 |
+
("relating_person", None),
|
| 710 |
+
),
|
| 711 |
+
Relation: (
|
| 712 |
+
("+", None),
|
| 713 |
+
("+", None),
|
| 714 |
+
("+", None),
|
| 715 |
+
("+", None),
|
| 716 |
+
("+", None),
|
| 717 |
+
("+", None),
|
| 718 |
+
("+", None),
|
| 719 |
+
("+", None),
|
| 720 |
+
("BasePerson_m2m_abstract+", None),
|
| 721 |
+
("BasePerson_m2m_base+", None),
|
| 722 |
+
("Person_m2m_inherited+", None),
|
| 723 |
+
("fk_abstract_rel", None),
|
| 724 |
+
("fk_base_rel", None),
|
| 725 |
+
("fk_concrete_rel", None),
|
| 726 |
+
("fo_abstract_rel", None),
|
| 727 |
+
("fo_base_rel", None),
|
| 728 |
+
("fo_concrete_rel", None),
|
| 729 |
+
),
|
| 730 |
+
},
|
| 731 |
+
"get_all_related_objects_with_model_proxy_legacy": {
|
| 732 |
+
BasePerson: (
|
| 733 |
+
("person", None),
|
| 734 |
+
("relating_baseperson", None),
|
| 735 |
+
),
|
| 736 |
+
Person: (
|
| 737 |
+
("relating_baseperson", BasePerson),
|
| 738 |
+
("relating_person", None),
|
| 739 |
+
("relating_proxyperson", None),
|
| 740 |
+
),
|
| 741 |
+
Relation: (
|
| 742 |
+
("fk_abstract_rel", None),
|
| 743 |
+
("fo_abstract_rel", None),
|
| 744 |
+
("fk_base_rel", None),
|
| 745 |
+
("fo_base_rel", None),
|
| 746 |
+
("fk_concrete_rel", None),
|
| 747 |
+
("fo_concrete_rel", None),
|
| 748 |
+
),
|
| 749 |
+
},
|
| 750 |
+
"get_all_related_objects_with_model_proxy_hidden_legacy": {
|
| 751 |
+
BasePerson: (
|
| 752 |
+
("+", None),
|
| 753 |
+
("BasePerson_following_abstract+", None),
|
| 754 |
+
("BasePerson_following_abstract+", None),
|
| 755 |
+
("BasePerson_following_base+", None),
|
| 756 |
+
("BasePerson_following_base+", None),
|
| 757 |
+
("BasePerson_friends_abstract+", None),
|
| 758 |
+
("BasePerson_friends_abstract+", None),
|
| 759 |
+
("BasePerson_friends_base+", None),
|
| 760 |
+
("BasePerson_friends_base+", None),
|
| 761 |
+
("BasePerson_m2m_abstract+", None),
|
| 762 |
+
("BasePerson_m2m_base+", None),
|
| 763 |
+
("Relating_basepeople+", None),
|
| 764 |
+
("Relating_basepeople_hidden+", None),
|
| 765 |
+
("person", None),
|
| 766 |
+
("relating_baseperson", None),
|
| 767 |
+
),
|
| 768 |
+
Person: (
|
| 769 |
+
("+", BasePerson),
|
| 770 |
+
("+", None),
|
| 771 |
+
("+", None),
|
| 772 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 773 |
+
("BasePerson_following_abstract+", BasePerson),
|
| 774 |
+
("BasePerson_following_base+", BasePerson),
|
| 775 |
+
("BasePerson_following_base+", BasePerson),
|
| 776 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 777 |
+
("BasePerson_friends_abstract+", BasePerson),
|
| 778 |
+
("BasePerson_friends_base+", BasePerson),
|
| 779 |
+
("BasePerson_friends_base+", BasePerson),
|
| 780 |
+
("BasePerson_m2m_abstract+", BasePerson),
|
| 781 |
+
("BasePerson_m2m_base+", BasePerson),
|
| 782 |
+
("Person_following_inherited+", None),
|
| 783 |
+
("Person_following_inherited+", None),
|
| 784 |
+
("Person_friends_inherited+", None),
|
| 785 |
+
("Person_friends_inherited+", None),
|
| 786 |
+
("Person_m2m_inherited+", None),
|
| 787 |
+
("Relating_basepeople+", BasePerson),
|
| 788 |
+
("Relating_basepeople_hidden+", BasePerson),
|
| 789 |
+
("Relating_people+", None),
|
| 790 |
+
("Relating_people_hidden+", None),
|
| 791 |
+
("relating_baseperson", BasePerson),
|
| 792 |
+
("relating_person", None),
|
| 793 |
+
("relating_proxyperson", None),
|
| 794 |
+
),
|
| 795 |
+
Relation: (
|
| 796 |
+
("+", None),
|
| 797 |
+
("+", None),
|
| 798 |
+
("+", None),
|
| 799 |
+
("+", None),
|
| 800 |
+
("+", None),
|
| 801 |
+
("+", None),
|
| 802 |
+
("+", None),
|
| 803 |
+
("+", None),
|
| 804 |
+
("BasePerson_m2m_abstract+", None),
|
| 805 |
+
("BasePerson_m2m_base+", None),
|
| 806 |
+
("Person_m2m_inherited+", None),
|
| 807 |
+
("fk_abstract_rel", None),
|
| 808 |
+
("fk_base_rel", None),
|
| 809 |
+
("fk_concrete_rel", None),
|
| 810 |
+
("fo_abstract_rel", None),
|
| 811 |
+
("fo_base_rel", None),
|
| 812 |
+
("fo_concrete_rel", None),
|
| 813 |
+
),
|
| 814 |
+
},
|
| 815 |
+
"get_all_related_many_to_many_with_model_legacy": {
|
| 816 |
+
BasePerson: (
|
| 817 |
+
("friends_abstract_rel_+", None),
|
| 818 |
+
("followers_abstract", None),
|
| 819 |
+
("friends_base_rel_+", None),
|
| 820 |
+
("followers_base", None),
|
| 821 |
+
("relating_basepeople", None),
|
| 822 |
+
("_model_meta_relating_basepeople_hidden_+", None),
|
| 823 |
+
),
|
| 824 |
+
Person: (
|
| 825 |
+
("friends_abstract_rel_+", BasePerson),
|
| 826 |
+
("followers_abstract", BasePerson),
|
| 827 |
+
("friends_base_rel_+", BasePerson),
|
| 828 |
+
("followers_base", BasePerson),
|
| 829 |
+
("relating_basepeople", BasePerson),
|
| 830 |
+
("_model_meta_relating_basepeople_hidden_+", BasePerson),
|
| 831 |
+
("friends_inherited_rel_+", None),
|
| 832 |
+
("followers_concrete", None),
|
| 833 |
+
("relating_people", None),
|
| 834 |
+
("_relating_people_hidden_+", None),
|
| 835 |
+
),
|
| 836 |
+
Relation: (
|
| 837 |
+
("m2m_abstract_rel", None),
|
| 838 |
+
("m2m_base_rel", None),
|
| 839 |
+
("m2m_concrete_rel", None),
|
| 840 |
+
),
|
| 841 |
+
},
|
| 842 |
+
"get_all_related_many_to_many_local_legacy": {
|
| 843 |
+
BasePerson: [
|
| 844 |
+
"friends_abstract_rel_+",
|
| 845 |
+
"followers_abstract",
|
| 846 |
+
"friends_base_rel_+",
|
| 847 |
+
"followers_base",
|
| 848 |
+
"relating_basepeople",
|
| 849 |
+
"_model_meta_relating_basepeople_hidden_+",
|
| 850 |
+
],
|
| 851 |
+
Person: [
|
| 852 |
+
"friends_inherited_rel_+",
|
| 853 |
+
"followers_concrete",
|
| 854 |
+
"relating_people",
|
| 855 |
+
"_relating_people_hidden_+",
|
| 856 |
+
],
|
| 857 |
+
Relation: [
|
| 858 |
+
"m2m_abstract_rel",
|
| 859 |
+
"m2m_base_rel",
|
| 860 |
+
"m2m_concrete_rel",
|
| 861 |
+
],
|
| 862 |
+
},
|
| 863 |
+
"private_fields": {
|
| 864 |
+
AbstractPerson: [
|
| 865 |
+
"generic_relation_abstract",
|
| 866 |
+
"content_object_abstract",
|
| 867 |
+
],
|
| 868 |
+
BasePerson: [
|
| 869 |
+
"generic_relation_base",
|
| 870 |
+
"content_object_base",
|
| 871 |
+
"generic_relation_abstract",
|
| 872 |
+
"content_object_abstract",
|
| 873 |
+
],
|
| 874 |
+
Person: [
|
| 875 |
+
"content_object_concrete",
|
| 876 |
+
"generic_relation_concrete",
|
| 877 |
+
"generic_relation_base",
|
| 878 |
+
"content_object_base",
|
| 879 |
+
"generic_relation_abstract",
|
| 880 |
+
"content_object_abstract",
|
| 881 |
+
],
|
| 882 |
+
},
|
| 883 |
+
"labels": {
|
| 884 |
+
AbstractPerson: "model_meta.AbstractPerson",
|
| 885 |
+
BasePerson: "model_meta.BasePerson",
|
| 886 |
+
Person: "model_meta.Person",
|
| 887 |
+
Relating: "model_meta.Relating",
|
| 888 |
+
},
|
| 889 |
+
"lower_labels": {
|
| 890 |
+
AbstractPerson: "model_meta.abstractperson",
|
| 891 |
+
BasePerson: "model_meta.baseperson",
|
| 892 |
+
Person: "model_meta.person",
|
| 893 |
+
Relating: "model_meta.relating",
|
| 894 |
+
},
|
| 895 |
+
}
|