Commit graph

401 commits

Author SHA1 Message Date
Nafees Anwar
a56d07cd68 Added urlsafe token field 2021-04-30 21:40:39 +05:00
Hasan Ramezani
2269f810c8 Fix TypeError in save when model inherits from both TimeStampModel and StatusModel. (Fixes GH-465) 2020-12-02 00:07:22 +01:00
David Smith
79ff8ea6be
Used isort to sort imports (#460) 2020-11-29 20:58:00 +00:00
Jannis Leidel
e630935fa3
Please coverage 2020-11-29 15:00:33 +01:00
Jannis Leidel
1336a91d75
Merge branch 'master' into gha 2020-11-29 14:42:23 +01:00
Jannis Leidel
2cd07a9e89
Use setuptools_scm 2020-11-29 14:39:17 +01:00
Hasan Ramezani
92ff6b927f Remove codes related to old versions of Django. 2020-11-28 21:46:25 +01:00
Ben Steinberg
eba26d6bd4 Fix typo 2020-10-29 09:11:30 -04:00
Arseniy Panfilov
e9c45c71d1 update implementation of TimeStampedModel.save to handle various ways of specifying 'update_fields' 2020-10-15 15:51:33 +06:00
Hasan Ramezani
be1c0f571e Add farsi translation. 2020-09-23 09:29:26 +06:00
H. Buğra Aydın
2ad67e77b1
Add status_changed field to upload_fields parameter during save if status field is present (#441)
* implementation/tests

* naming problem
2020-09-17 20:34:57 +06:00
Craig Anderson
b7a160936f Add available_objects soft deletable model manager. Emit deprecation warning when using objects soft deletable manager. 2020-08-25 16:40:09 +06:00
Skia
33e46ebd53 managers: avoid querying too much tables when not needed
When calling `select_related()` with an empty list of arguments [1], Django will
try to prefetch some data by doing some first level joints with the related
classes.
This can lead to obvious negative performance impact, but this also breaks some
workarounds for having inheritance for foreign keys [2], as those solutions rely
on lazy evaluation of the related object.

[1]: a4e6030904/django/db/models/query.py (L1051)
     Only passing an explicit `None` to `select_related` will disable the magic.
[2]: https://github.com/jazzband/django-model-utils/issues/11

As examples, here are the generated SQL requests in
InheritanceManagerRelatedTests.test_get_method_with_select_subclasses_check_for_useless_join:

  * without this fix, without adding `.select_related(None)`
```sql
SELECT
    "tests_inheritancemanagertestparent"."id",
    "tests_inheritancemanagertestparent"."non_related_field_using_descriptor",
    "tests_inheritancemanagertestparent"."related_id",
    "tests_inheritancemanagertestparent"."normal_field",
    "tests_inheritancemanagertestparent"."related_self_id",
    "tests_inheritancemanagertestchild4"."other_onetoone_id",
    "tests_inheritancemanagertestchild4"."parent_ptr_id", T3."id",
    T3."non_related_field_using_descriptor", T3."related_id", T3."normal_field",
    T3."related_self_id"
FROM
    "tests_inheritancemanagertestchild4"
INNER JOIN
    "tests_inheritancemanagertestparent" ON
    ("tests_inheritancemanagertestchild4"."parent_ptr_id" = "tests_inheritancemanagertestparent"."id")
INNER JOIN
    "tests_inheritancemanagertestparent" T3 ON
    ("tests_inheritancemanagertestchild4"."other_onetoone_id" = T3."id")
WHERE
    "tests_inheritancemanagertestchild4"."parent_ptr_id" = 191
```

  * with either the fix, or by adding `.select_related(None)` after `.select_subclasses()`
```sql
SELECT
    "tests_inheritancemanagertestparent"."id",
    "tests_inheritancemanagertestparent"."non_related_field_using_descriptor",
    "tests_inheritancemanagertestparent"."related_id",
    "tests_inheritancemanagertestparent"."normal_field",
    "tests_inheritancemanagertestparent"."related_self_id",
    "tests_inheritancemanagertestchild4"."other_onetoone_id",
    "tests_inheritancemanagertestchild4"."parent_ptr_id"
FROM
    "tests_inheritancemanagertestchild4"
INNER JOIN
    "tests_inheritancemanagertestparent" ON
    ("tests_inheritancemanagertestchild4"."parent_ptr_id" = "tests_inheritancemanagertestparent"."id")
WHERE
    "tests_inheritancemanagertestchild4"."parent_ptr_id" = 191

```
2020-07-08 16:59:05 +06:00
skazancev
bf4b65a437 removed model from DeferredAttributeTracker 2020-05-28 22:40:13 +06:00
Martín Raúl Villalba
6fba04ec4f Satisfy deprecation warning under Django 3.0.3 2020-03-01 08:55:31 +06:00
H. Buğra Aydın
3e32ae257b Overriding TimeStampedModel's save() method (#412)
* Overriding TimeStampedModel's save() method

to update modified field automatically when update_fields argument is used but modified was not given as a parameter.

* fixed a small error in logic

* added tests for new functionality
2020-01-23 13:19:06 +06:00
Sergey Tikhonov
1386c379b7 FieldTracker should patch save_base instead of save (#404)
* add test for reproducing FieldTracker update_fields issue

FieldTracker does not see update_fields changed in tracked model.save() method

* Patch Model.save_base instead of save

This change allows proper capturing update_fields kwarg if is is changed in overridden save() method.

* Add some details about FieldTracker implementation

* Mention FieldTracker behavior change
2019-12-15 22:43:58 +06:00
Sergey Tikhonov
d756a4a8ce patch Model.refresh_from_db in FieldTracker (#403)
* patch Model.refresh_from_db in FieldTracker

* add info about refresh_from_db patching to CHANGES.rst
2019-12-15 20:28:15 +06:00
Rémy HUBSCHER
35ba2bde31
Back to development 4.0.1 2019-12-11 15:48:26 +01:00
Misha K
5aa40c66be Add django 3.0 to the test matrix and drop six (#395)
*  - add django 3.0 to the test matrix
 - drop six

* add entry in CHANGES

* remove context kwarg

* fix test with DeferredAttribute

* rename StringyDescriptor's name to attname

* Fix flake8

* Drop support for Django 1.11 because the API are not compatibles anymore with Django 3.0

* Try to fix tests.

* Define model for the field mock.

* Simplifies the code.

* Properly mock the field.

* Typo

* Use the new API field name.

* Call it attname

* Grab the field instance from the model.

* Use postgres in travis tests.

* Django 2.0.1 minimum is needed.

* Update Changelog to tell about breaking Django 1.11.

* Update changelog to tell about Django 3.0 support.

* @natim review.
2019-12-09 19:37:16 +06:00
Adam Dobrawy
ffa1a85dc7 Modernize Python syntax, add Python 3.8 (#398)
* Modernize Python syntax, add Python 3.8

* Update Python version & dist in TravisCI

* Add postgresql as addon

* Switch to psycopg2-binary

* Drop django.utils.six
2019-11-14 22:50:04 +06:00
Hasan Ramezani
aa94194dbc Drop Python 2 support. (#394) 2019-09-30 14:08:52 +06:00
Rémy HUBSCHER
c19ea5b04f
Add changelog. 2019-08-21 11:19:13 +02:00
Rémy HUBSCHER
e6c7b567d1
Remove unsupported django version hacks. 2019-08-21 11:02:23 +02:00
Asif Saif Uddin
d901b233d3
Merge pull request #387 from jazzband/instance-of
Add ability to filter an InheritanceQuerySet by model.
2019-08-20 23:45:02 +06:00
Rémy HUBSCHER
1878537f25
Merge branch 'master' into bugfix/issue_109 2019-08-20 13:46:07 +02:00
Rémy HUBSCHER
976c17024e
Merge branch 'master' into instance-of 2019-08-20 12:50:09 +02:00
Asif Saif Uddin
d3534d656d
Merge pull request #384 from Asday/subset
Added `Choices().subset()`.
2019-08-20 05:02:47 +06:00
asday
488be3ff01 Updated documentation and bumped minor version. 2019-08-19 23:02:43 +01:00
asday
1142254f62 not x in y => x not in y. 2019-08-19 22:38:30 +01:00
asday
d9aa34e498 Fixed spacing.
Extraneous whitespace, too many blank lines, and too few blank
lines.
2019-08-19 22:38:05 +01:00
asday
51a720386c Moved a binary operator to the start of a line. 2019-08-19 22:37:16 +01:00
asday
383740e8ab Added Choices().subset(). 2019-08-19 22:33:08 +01:00
Emin Bugra Saral
5d6f8f4e9f Disable signals on save feature 2019-05-20 19:35:05 +02:00
Asif Saif Uddin
25dde41418
Merge pull request #360 from marfyl/master
Add UUIDModel and UUIDField
2019-05-16 05:45:53 +06:00
Jack Cushman
f2e97e4141 Move patch_save to finalize_class so it works on models with save() methods 2019-04-25 17:50:08 -04:00
Nick Sandford
d557c42533 Catch deferred attribute exception (#367) 2019-03-29 12:46:40 +06:00
Skia
1b9b5ac2c1 managers: honor OneToOneField.parent_link=False (#363) 2019-03-12 23:29:02 +06:00
jmmp
5ffcfe831c
Update fields.py 2019-02-27 02:29:47 +01:00
JMP
ce3a0e59f4 Use django exception instead custom one 2019-02-26 19:17:06 +01:00
JMP
2a47aa093d Pep8 review 2019-02-26 19:01:39 +01:00
JMP
da3c59a6df Fix SyntaxError for python 2.7 2019-02-26 18:38:39 +01:00
JMP
0d4facbb53 Merge branch 'feature/uuid_model' of github.com:marfyl/django-model-utils into feature/uuid_model 2019-02-26 18:01:20 +01:00
jmmp
e5955f780b
Update fields.py 2019-02-26 17:58:20 +01:00
JMP
2f142afd37 Fix imports pep8 2019-02-26 17:55:02 +01:00
JMP
015dd4831f Catch error with inherit class 2019-02-26 17:50:32 +01:00
JMP
533501753f UUID version custom exception 2019-02-26 17:36:59 +01:00
JMP
ca75294883 UUID field added 2019-02-26 17:33:06 +01:00
JMP
38f8932e74 UUID model added 2019-02-26 17:32:56 +01:00
Zach Cheung
af1824e200 fix conflict 2019-01-11 17:26:06 +08:00