Commit Graph

189 Commits

Author SHA1 Message Date
Shai Berger 72ebe85a26 Fixed #27910 -- Added enumeration helpers for use in Field.choices.
These classes can serve as a base class for user enums, supporting
translatable human-readable names, or names automatically inferred
from the enum member name.

Additional properties make it easy to access the list of names, values
and display labels.

Thanks to the following for ideas and reviews:

Carlton Gibson, Fran Hrženjak, Ian Foote, Mariusz Felisiak, Shai Berger.

Co-authored-by: Shai Berger <shai@platonix.com>
Co-authored-by: Nick Pope <nick.pope@flightdataservices.com>
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2019-09-04 14:42:49 +02:00
Nick Pope 21e559495b Fixed #29979, Refs #17337 -- Extracted AutoField field logic into a mixin and refactored AutoFields.
This reduces duplication by allowing AutoField, BigAutoField and
SmallAutoField to inherit from IntegerField, BigIntegerField and
SmallIntegerField respectively. Doing so also allows for enabling the
max_length warning check and minimum/maximum value validation for auto
fields, as well as providing a mixin that can be used for other possible
future auto field types such as a theoretical UUIDAutoField.
2019-08-20 09:22:25 +02:00
zeyneloz 00035672a4 Fixed #30449 -- Fixed RelatedFieldListFilter/RelatedOnlyFieldListFilter to respect model's Meta.ordering.
Regression in 6d4e5feb79.

Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2019-08-15 10:29:05 +02:00
Diederik van der Boor 25f21bd237 Fixed #28393 -- Added helpful error messages for invalid AutoField/FloatField/IntegerField values.
Co-authored-by: Diederik van der Boor <vdboor@edoburu.nl>
Co-authored-by: Nick Pope <nick.pope@flightdataservices.com>
2019-08-05 08:41:29 +02:00
Jon Dufresne 42b9a23267 Fixed #30400 -- Improved typography of user facing strings.
Thanks Claude Paroz for assistance with translations.
2019-06-28 16:46:18 +02:00
Jon Dufresne 498092377b Refs #27804 -- Used subTest() in BinaryFieldTests.test_set_and_retrieve. 2019-06-07 06:04:56 +02:00
Mykola Kokalko ef082ebb84 Fixed #29529 -- Allowed models.fields.FilePathField to accept a callable path. 2019-05-02 11:11:56 +02:00
Mykola Kokalko 11971cd87c Added tests for setting models.fields.FilePathField.path. 2019-05-02 11:11:50 +02:00
Scott Fitsimones a14c0fda15 Fixed #30328 -- Fixed crash of IntegerField.validators when limit_value in a custom validator is callable. 2019-04-19 07:58:27 +02:00
Matthias Kestenholz ea60b7bc74 Removed redundant model field choices tests. 2019-03-23 12:04:39 -04:00
Simon Charette 218a485bf1 Refs #12663 -- Fixed reference to nonexistent field in model_fields tests. 2019-03-17 20:49:32 -04:00
avas9366 9681e968eb Fixed #30232 -- Corrected expected format in invalid DurationField error message. 2019-03-04 19:25:27 -05:00
Joshua Cannon 16a5a2a2c8 Fixed #30076 -- Added Model.get_FOO_display() even if field's choices are empty. 2019-01-30 13:44:10 -05:00
Simon Charette 84e7a9f4a7 Switched setUp() to setUpTestData() where possible in Django's tests. 2018-11-27 09:35:17 -05:00
Tim Graham 193c109327 Switched TestCase to SimpleTestCase where possible in Django's tests. 2018-11-27 08:58:44 -05:00
Hasan Ramezani 6d4e5feb79 Fixed #29835 -- Made RelatedFieldListFilter respect ModelAdmin.ordering. 2018-11-14 14:29:39 -05:00
Sanyam Khurana 83c7096f2a Fixed #29869 -- Made UUIDField.to_python() convert integers. 2018-10-24 20:26:57 -04:00
Simon Charette 5e3463f6bc Fixed #27595 -- Made ForeignKey.get_col() follow target chains.
Previously, foreign relationships were followed only one level deep which
prevents foreign keys to foreign keys from being resolved appropriately.
This was causing issues such as improper database value conversion for
UUIDField on SQLite because the resolved expression's output field's
internal type wasn't correct. Added tests to make sure unlikely foreign
reference cycles don't cause recursion errors.

Refs #24343.

Thanks oyooyo for the report and Wayne Merry for the investigation.
2018-10-22 09:49:34 -04:00
Jon Dufresne b3b47bf515 Added tests for using bytearray with BinaryField and corrected docs. 2018-10-01 09:16:16 -04:00
Sergey Fedoseev 8ef8bc0f64 Refs #28909 -- Simplifed code using unpacking generalizations. 2018-09-28 09:57:12 -04:00
Jon Dufresne fb2964a410 Added test of filtering on BinaryField and corrected docs. 2018-09-26 14:38:12 -04:00
orlnub123 21420096c4 Fixed #29247 -- Allowed blank model field choice to be defined in nested choices. 2018-04-20 11:06:14 -04:00
Tim Graham e35004966b Moved tests for model Field.get_choices(). 2018-04-20 11:05:25 -04:00
Tim Graham 5fa4f40f45 Fixed #29227 -- Allowed BooleanField to be null=True.
Thanks Lynn Cyrin for contributing to the patch, and Nick Pope for review.
2018-03-20 12:10:10 -04:00
Mariusz Felisiak 362813d628
Fixed hanging indentation in various code. 2018-03-16 10:54:34 +01:00
Sergey Fedoseev ae6fa914aa Fixed #28926 -- Fixed loss of precision of big DurationField values on SQLite and MySQL. 2017-12-28 17:35:41 -05:00
Cameron Curry 622ead6aaf Fixed #28937 -- Allowed BinaryField to be editable=True. 2017-12-22 16:31:46 -05:00
Sergey Fedoseev 6fd6d8383f Fixed #28915 -- Prevented SQLite from truncating trailing zeros in the fractional part of DecimalField.
This reverts commit a146b65628 and adds
a test for the regression.
2017-12-12 21:57:41 -10:00
Simon Charette e50add6ca1 Fixed #28856 -- Fixed a regression in caching of a GenericForeignKey pointing to a MTI model.
Regression in b9f8635f58.
2017-11-30 09:28:44 -05:00
Sergey Fedoseev b5ecbf1e12 Simplified choices iterators in tests.model_fields.models. 2017-11-13 13:11:07 -05:00
Tim Graham dd82f33271 Fixed #27979 -- Made MySQL raise IntegrityError rather than OperationalError when saving negative numbers in PositiveInteger fields. 2017-09-29 15:20:32 -04:00
Tim Graham a80903b711 Removed DatabaseFeatures.supports_microsecond_precision.
MySQL 5.5 (refs #28552) was the last database to use it.
2017-09-25 14:48:15 -04:00
Tim Graham e5bd585c6e Fixed #28543 -- Prevented ManyToManyField.value_from_object() from being lazy.
Previously, it was a QuerySet which could reevaluate to a new value if the
model's data changes. This is inconsistent with other Field.value_from_object()
methods.

This allows reverting the fix in the admin for refs #27998.
2017-08-31 09:34:44 -04:00
Mads Jensen a51c4de194 Used assertRaisesMessage() to test Django's error messages. 2017-07-29 19:07:23 -04:00
Sergey Fedoseev 37fbeb99f9 Removed unused models.DecimalField._format().
Unused since b3b71a0922.
2017-07-20 09:00:18 -04:00
Jon Dufresne fa283067c9 Removed unnecessary empty parentheses in class definitions. 2017-06-26 10:31:32 -04:00
Maciej Jaworski dc63ad7ac0 Fixed #28319 -- Made TextField with choices use a Select widget. 2017-06-17 08:23:32 -04:00
chillaranand fb0f987f7d Fixed #27914 -- Added support for nested classes in Field.deconstruct()/__repr__(). 2017-06-14 10:10:17 -04:00
Collin Anderson 7c9cb1ed37 Refs #27953 -- Removed hardcoded uses of Model.__str__() in tests. 2017-06-09 13:28:50 -04:00
Manatsawin Hanmongkolchai a0c07d77fc Fixed #28242 -- Moved ImageField file extension validation to the form field. 2017-06-01 10:13:23 -04:00
Ingo Klöcker 6bb3b2bff4 Refs #27777 -- Improved docs/added test for File context manager change. 2017-05-31 21:02:58 -04:00
Tim Graham a9874d48b1 Fixed #28188 -- Fixed crash when pickling model fields.
Regression in d2a26c1a90.

Thanks Adam Alton for the report and test, and Adam Johnson for
suggesting the fix.
2017-05-11 21:04:52 -04:00
Florian Apolloner d611a89238 Decreased max_length for char fields unless absolutely needed. (#8485) 2017-05-10 17:33:46 +02:00
Claude Paroz a87189fc5e Fixed #28164 -- Improved float conversions in DecimalField.to_python
Thanks Tim Graham and Adam Johnson for the reviews.
2017-05-09 08:40:08 +02:00
Tim Graham c920db1e57 Removed blank line in tests/model_fields/test_decimalfield.py per isort. 2017-04-29 07:42:12 -04:00
Mariusz Felisiak f32ee6d0ec Refs #6767 -- Added test for fetching decimal values without rounding error on Oracle. 2017-04-28 06:07:28 +02:00
Kapil Garg 7e09fa7f51 Fixed #27969 -- Fixed models.Field.formfield() setting 'disabled' for fields with choices. 2017-03-23 13:22:04 -04:00
Claude Paroz 8346680e1c Refs #27795 -- Removed unneeded force_text calls
Thanks Tim Graham for the review.
2017-03-04 18:18:21 +01:00
ClairePhila d26413113c Refs #27148 -- Fixed UUIDField.to_python(None) crash.
Regression in 2f9861d823.
2017-02-10 13:54:52 -05:00
Claude Paroz 068cd60366 Removed unneeded parentheses in class definitions 2017-01-29 18:06:26 +01:00