Commit Graph

449 Commits (d93f17846fb8a36c9f2bd83a80e0729297d4394f)

Author SHA1 Message Date
Diederik van der Boor a6aa95c07e Fixed internal usage of deprecated `base_objects`
Reverted the change in f898f80594 that
also replaces the internal `base_objects` with `.non_polymorphic()`.
That also changed which querysets was used. Use a clean queryset
instead that has no select-related/prefetch information, etc.. like
previous versions did.
2018-02-05 13:00:23 +01:00
Diederik van der Boor 852ecf6ea9 Turn the manager inheritance error into a warning.
Not all projects have queryset issues, for example the class could be a
leaf that doesn't get inherited further.

  class PolymorphicModel
    class ContentItem
      class TextItem   <-- gets error, but it's the leaf anyway.
2018-02-05 10:19:18 +01:00
Diederik van der Boor f898f80594 Fixed unwanted manager replacement in Django 1.11 projects.
Django 1.11 uses the old manager inheritance system, unless it's
overwritten with manager_inheritance_from_future. With a class layout
like:

  PolymorphicModel  (abstract)
    PolymorphicMPTTModel  (abstract)
      GenericCustomer  (concrete, has objects = ...)
        CustomerGroupBase (abstract, has objects = ...)
          Partner (concrete, no manager)
            BranchPartner  (concrete, no manager)

The last level gets a normal Django Manager instead of the polymorphic
manager. Because the PolymorphicModel had a base_objects manager, this
was typically used as _default_manager. Now that the default manager is
no longer affected, it's also easier to detect why the "objects" doesn't
get the proper manager type. Using "manager_inheritance_from_future" is
recommended instead to have both the right behavior and forward
Django 2.x compatibility.
2018-02-04 13:22:51 +01:00
Diederik van der Boor f7c9df935f move _polymorphic_iterator to PolymorphicModelIterable as there is no second compatibility code path anymore 2018-01-22 15:22:27 +01:00
Diederik van der Boor 9d651a1cdb Fix the add_media() hack for Django 2.0 2018-01-18 15:45:18 +01:00
Charlie Denton ed40b9e3e2
Use assertRegex to ignore object IDs
Sometimes the tests failed because these objects had IDs that differed
from expectations. As the IDs are not relevant to this test, I have
replaced the exact string match with a regex match that accepts any ID.
2018-01-17 22:02:19 +00:00
Charlie Denton ca13180a61
Clean up unrequired compat import 2018-01-16 10:54:33 +00:00
Charlie Denton 3f6d94139c
Remove unused function in tests 2018-01-16 10:54:33 +00:00
Charlie Denton e2bf741d5d
Remove models that are not referenced in tests
This silences one instance of the warning that's being printed in tests
for versions of Django before 2.0:

> RemovedInDjango20Warning: Managers from concrete parents will soon
> qualify as default managers if they appear before any other managers
> in the MRO.
2018-01-16 10:53:35 +00:00
Charlie Denton 120520e44d
Fix `add_media` util for Django 2.0
Neither `add_css` nor `add_js` exist in Django 2.0 because the method
for adding `Media` classes together has changed.

Ref: c19b56f633
2018-01-16 10:53:34 +00:00
Charlie Denton 1a4595f5ce
Fix deprecated admin site URL in tests
The old format was deprecated in Django 1.9, and removed in Django 2.0.

Ref: https://docs.djangoproject.com/en/stable/releases/1.9/#passing-a-3-tuple-or-an-app-name-to-include
2018-01-16 10:53:34 +00:00
Charlie Denton 840bfe8d22
Fix import in Django 2.0
Because the URL mechanism has changed in Django 2.0, the
RegexURLResolver has been renamed.
2018-01-16 10:53:34 +00:00
Diederik van der Boor 7fe7861f45 Amend PR #336: fix migration file syntax for Django 1.10 2018-01-15 15:08:14 +01:00
Diederik van der Boor 38a91a8622
Merge pull request #336 from reef-technologies/bulk_create_support
Bulk create support
2018-01-15 15:03:48 +01:00
Krzysztof Gromadzki 8dc9bd2543 Review applied 2017-12-31 17:14:23 +01:00
Krzysztof Gromadzki 010a23425f Add support for bulk_create 2017-12-29 19:05:57 +01:00
Diederik van der Boor a2ba52517f Improve fix of PR #321
checking hasattr(self, 'fieldsets') alway returns true, and produces
different effects. The hasattr(self, 'declared_fieldsets') was designed
to detect whether Django injected that attribute.

Amends: 5e150ea85a
2017-12-22 10:03:13 +01:00
Tadas Dailyda 180df8e98c fix detecting whether childadmin has explicitly defined fields/fieldsets 2017-11-20 17:39:34 +02:00
Tadas Dailyda 15426dc695 further childadmin fieldsets improvements 2017-11-20 17:38:02 +02:00
Diederik van der Boor 02b71d8ba9 Improve fix of PR #321
checking hasattr(self, 'fieldsets') alway returns true, and produces
different effects. The hasattr(self, 'declared_fieldsets') was designed
to detect whether Django injected that attribute.

Amends: 5e150ea85a
2017-11-20 15:22:58 +01:00
Diederik van der Boor 8f0932b71e Fixed applabel__ModelName___field looksups
Closes: #286
2017-11-20 15:19:21 +01:00
Tadas Dailyda 5e150ea85a do not use deprecated and removed declared_fieldsets attribute in admin 2017-11-02 15:13:17 +02:00
Diederik van der Boor 04b5fb423c Make sure reset_polymorphic_ctype() supports proxy models 2017-10-08 22:43:54 +02:00
Diederik van der Boor c2768f8101 Fix support for proxy models in formsets and admin inlines 2017-10-08 22:43:54 +02:00
Diederik van der Boor cafaf95f06 Add UnsupportedChildType error for formsets
This also replaces the PolymorphicInlineModelAdmin.get_get_child_inline_instance()
and BasePolymorphicModelFormSet._construct_form() lookup with UnsupportedChildType
2017-10-08 22:33:01 +02:00
Diederik van der Boor 4d5fb4be3b fix indenting 2017-10-08 21:53:02 +02:00
Diederik van der Boor 3fe17d7a23 Provide helpful assistence to migrate code to new 1.0+ format
This makes sure the changes in 4dc20a0213
don't cause a new range of bug reports, for things like "reverse()" no
longer works.
2017-10-08 19:40:39 +02:00
Oleg Myltsyn 075f457045 Removed unnecessary translation comments (#316) 2017-10-07 01:28:34 +03:00
Diederik van der Boor 30630647c4 Add extra comment why deferred fields are skipped with ___ lookups 2017-09-30 20:26:52 +02:00
Diederik van der Boor 2e16112cbe Merge branch 'fix-defer-childs-same-polymorphic-parent' into master 2017-09-30 20:26:37 +02:00
Diederik van der Boor fb80233c5d Fix one Django-master error 2017-09-30 18:57:31 +02:00
Diederik van der Boor fab687c218 Workaround RTD error to generate the API pages 2017-09-30 18:47:03 +02:00
Diederik van der Boor c795c18575 Add admin history, add type, and add page tests 2017-09-30 18:33:19 +02:00
Diederik van der Boor a950049356 Improved and added more admin test cases 2017-09-30 18:16:59 +02:00
Diederik van der Boor 8d4cb9b151 Added rudimentary admin test cases 2017-09-30 17:47:02 +02:00
Diederik van der Boor 8caac2e57b Fixed the polymorphic inline script code.
Got broken in 0c7b1aa657 when removing
Djagno 1.8 compatibility
2017-09-30 16:50:12 +02:00
Diederik van der Boor 9f6e0716f6 Fix deleteText of |as_script_options 2017-09-30 16:46:26 +02:00
Diederik van der Boor c437524876 Improve docs of PolymorphicChildModelAdmin attributes 2017-09-30 16:35:21 +02:00
Diederik van der Boor cf0cb2478f Make the admin `base_model` setting optional.
It can be detected using get_base_polymorphic_model()
2017-09-30 16:35:02 +02:00
Diederik van der Boor 04d4181e17 Added `get_base_polymorphic_model()` to detect the common base class for a polymorphic model. 2017-09-30 16:21:21 +02:00
Diederik van der Boor 6febf7a069 Merge pull request #303 from WhyNotHugo/pgtests
Run CI with postgres too
2017-09-30 15:52:31 +02:00
Omer Strumpf bc11934c31 allowing extra arguments in get_inline_formsets 2017-09-28 12:22:13 +03:00
Hugo Osvaldo Barrera e102a0502c Update a bunch of failing tests
Tests were failing because of:

* Models weren't being imported from their new location.
* PolymorphicManager doesn't work with non-polymorphic models, but
  migrations run models' manager, so having MROBase3 with
  PolymorphicManager failed.
* Some tests failed due to have assertions were being done (since they
  hardcoded expected instance ids). Update tests to use comparisons
  similar to #312
2017-09-06 20:06:25 -03:00
Hugo Osvaldo Barrera a507345c6d Move test models into models.py and add migrations
Tests were failing on postgres due to foreign keys pointing to missing
tables.
In order for these tables to be present, we need migrations which
declare depending on `content_type`.
2017-09-06 19:47:18 -03:00
Hugo Osvaldo Barrera 80b4f2bb41 Fix failing tests with django/master
Several tests were failing with django master. This is because,
apparently, IDs don't match those expected in tests, and other
test-related details.

Replace all test comparisons with assertQuerysetEqual, which is safer
and cleaner for the sort of comparison we're doing.
2017-09-06 22:41:13 +03:00
trbs 9500a21f82 fix error with .defer and child models that use the same parent
When using .defer on a PolymorphicQuerySet with multiple childs that
subclass from the same polymorphic parent model yield an error like:

>>> Base.objects.defer('ModelY___field_y')
Traceback (most recent call last):
...
FieldDoesNotExist: ModelX has no field named 'field_y'
2017-08-30 21:17:05 +02:00
Jerome Leclanche 3af5db0ceb tests: Clean up and simplify test_reset_polymorphic_ctype 2017-08-29 19:41:42 +03:00
Jerome Leclanche a91a04af6b Set polymorphic.__version__ from setuptools metadata 2017-08-29 19:41:42 +03:00
Jerome Leclanche 300e9b062e Use field.remote_field instead of field.rel
Deprecated in Django 1.9, removed in 2.0

More information:
- https://docs.djangoproject.com/en/1.11/releases/1.9/#field-rel-changes
2017-08-29 19:41:42 +03:00
Jerome Leclanche fc8cabfa26 Replace use_for_related_fields by Meta.base_manager_name
Deprecated in 1.10, removed in 2.0

More information:
- https://code.djangoproject.com/ticket/14891
- django/django@ed0ff913c6
2017-08-29 19:41:42 +03:00
Jerome Leclanche 6fe1e2ddae Update django.urls imports 2017-08-29 19:41:42 +03:00
Jerome Leclanche 4dc20a0213 Remove Pre-1.0 compatibility hacks 2017-08-29 19:41:42 +03:00
Jerome Leclanche 0c7b1aa657 Drop support for Django 1.8 2017-08-29 19:41:42 +03:00
Diederik van der Boor 77797bfa12 Ensure consistent ordering in testing reset_polymorphic_ctype
Amends: 171d14f369
2017-08-01 13:51:42 +02:00
Diederik van der Boor 171d14f369 Improve reset_polymorphic_ctype() for reliability and test it.
This function can now be safely used on a set of models.
2017-08-01 12:17:10 +02:00
Diederik van der Boor e10deeaebd Remove test imports that Django 1.5- required 2017-08-01 12:17:10 +02:00
Diederik van der Boor 4835cd244e Also introduce a new exception type for invalid database IDs 2017-08-01 11:44:21 +02:00
Diederik van der Boor fb8eed78ad Provide a better error message when polymorphic_ctype_id is Null
refs #51, #140, #304
2017-08-01 11:44:21 +02:00
Diederik van der Boor b772c06358 move contrib tests to separate file 2017-08-01 11:44:21 +02:00
Diederik van der Boor fe0880e413 Merge pull request #300 from nazarewk/patch-1
`declared_fieldsets` typo fix
2017-08-01 11:38:13 +02:00
Diederik van der Boor b9ee2c7ab6 Merge pull request #307 from skirsdeda/master
Swapped polymorphic models don't work on Django>=1.10
2017-08-01 11:19:37 +02:00
Diederik van der Boor 1ce58a0b54 Bump to v1.3 - note: support for old Django versions dropped! 2017-08-01 11:07:24 +02:00
Tadas Dailyda 02330a5ec8 skip manager validation on swapped models 2017-07-25 14:11:37 +03:00
Tadas Dailyda 0fea8a4d92 tests for abstract/swappable model initialization 2017-07-25 14:02:15 +03:00
Diederik van der Boor 67dd5c0a0d Reverted int/long change, as Django's BigIntegerField can produce longs on Python 2 2017-07-10 10:57:07 +02:00
Jerome Leclanche 87979a6660 Remove outdated 404 url from docstrings 2017-07-10 09:08:11 +03:00
Jerome Leclanche 0a495cb485 Fix PolymorphicParentModelAdmin.pk_regex escape 2017-07-10 09:08:11 +03:00
Jerome Leclanche 1e7237986c Specify on_delete argument for all related fields that need it 2017-07-10 09:08:11 +03:00
Jerome Leclanche 298460c4cf Drop support for Django <1.8, Python <2.7 2017-07-10 09:08:11 +03:00
Krzysztof Nazarewski 697df65c7b `declared_fieldsets` typo fix 2017-07-05 13:45:28 +02:00
Diederik van der Boor b4b020bf2d Merge pull request #293 from NeveHanter/fix-po-files
Fixed PO files which resulted in SyntaxError when parsed by polib
2017-06-20 12:07:30 +02:00
Jerome Leclanche 544f5edef4 Fix accessor replacement consistency on Django 1.11
At this point, we don't know why this line of code is executed, but
we do know it's not consistently executed between Django 1.10 and
Django 1.11 due to the addition of `ForwardOneToOneDescriptor`, a
subclass of `ForwardManyToOneDescriptor`.

Refs. 6628145af7
Refs. kavdev/dj-stripe#524
Refs. django/django@38575b007a
2017-06-07 13:27:50 +03:00
Kamil Bar 2ece6ba582 Fixed PO files which resulted in SyntaxError when parsed by polib 2017-06-05 12:55:20 +02:00
Diederik van der Boor bcb8b0d3a4 Allow .order_by() to pass expressions unchanged
Fixes: #257
2017-05-22 12:53:20 +02:00
Charlie Denton 6f733d7471
Fix minor typo 2017-05-07 22:19:50 +01:00
Diederik van der Boor 44d79b5a19 Fixed Python 2.6 support in test code 2017-05-01 12:45:43 +02:00
Diederik van der Boor 21d41100df Bump to v1.2 for Django 1.11 support 2017-05-01 12:35:47 +02:00
Diederik van der Boor 9c618d8b21 Improve tests to use a unified qrepr() output 2017-05-01 12:34:49 +02:00
Diederik van der Boor 61b398115b Fixed queryset processing for real (another merge fix for pr #279) 2017-04-26 16:44:54 +02:00
Diederik van der Boor 09d785f5bb Fix infinite recursion on github editing of pr #279
Fixes: 89632483a7
2017-04-26 16:38:26 +02:00
Diederik van der Boor 89632483a7 Merge branch 'master' into dj111-fix 2017-04-26 15:53:59 +02:00
un.def 78d3cd4945 Fix regression with Django < 1.9 2017-04-19 14:43:51 +03:00
un.def dbad7bd40d Migrate from unused in Django 1.11 qs.iterator() to custom qs._iterable_class 2017-04-19 12:56:04 +03:00
Charlie Denton f010c6ddf7
Get tests running on django 1.11
I'm a little concerned that this loses some of the efficiencies (in
particular, chunking) from previous versions. That's something that can
probably be improved.
2017-04-12 23:52:06 +01:00
Diederik van der Boor a568c04e40 Merge pull request #262 from pawelad/patch-1
Added 'z-index' attribute to '.polymorphic-type-menu' CSS class
2017-04-06 14:15:45 +02:00
Diederik van der Boor a8bfb5007e Fix TypeError on Python 3 when querystring is preserved in the admin.
Fixes: #263
2017-04-06 14:13:56 +02:00
Diederik van der Boor a3c9bcb14a Merge remote branch 'meshy/new-test-versions' 2017-04-06 13:57:07 +02:00
Diederik van der Boor d8cb700e58 Make sure tests can run in Django 1.11 2017-04-06 12:51:16 +02:00
Diederik van der Boor cd38e785b2 Add an explicit exclude for polymorphic_ctype in the PolymorphicInlineModelAdmin 2017-04-06 12:47:28 +02:00
Charlie Denton aefb7dabc2
Django 1.11 uses real class names in __repr__()
See https://code.djangoproject.com/ticket/27546 and
https://github.com/django/django/commit/48826aa
2017-03-03 22:56:09 +00:00
Charlie Denton 8e52bdf6d1
Explicitly name ids of clashing base models
This avoids the following error in django 1.11 tests:

    polymorphic.MRODerived: (models.E005) The field 'id' from parent model 'polymorphic.mrobase3' clashes with the field 'id' from parent model 'polymorphic.mrobase1'.

Related to https://code.djangoproject.com/ticket/22442
2017-03-03 22:16:54 +00:00
Paweł Adamczak 54b681c13b Added 'z-index' attribute to '.polymorphic-type-menu' CSS class 2017-02-06 15:06:58 +00:00
Diederik van der Boor 132e2cfdf9 Bump to v1.1 2017-02-03 22:08:48 +01:00
Diederik van der Boor 7dc2f93148 Added plain tests for admin importing 2017-02-03 22:05:13 +01:00
Diederik van der Boor b691533039 Fix import errors with Django 1.6 code 2017-02-03 22:05:13 +01:00
Diederik van der Boor 66619371fd remove empty test_models.py file 2017-02-03 22:05:13 +01:00
Diederik van der Boor ed09e4db93 Fixed Python 2.6 issue 2017-02-03 21:44:38 +01:00
Diederik van der Boor d11bb17809 Bump to v1.1b: 2017-01-11 14:18:38 +01:00
Diederik van der Boor 04f2a62fd4 Revert get_real_concrete_instance_class_id() dry attempt
Caused by f9fffc44c1
2017-01-11 14:17:26 +01:00
Diederik van der Boor e06aa6ae80 Bump to v1.1b1 2017-01-10 17:19:44 +01:00