Let model extensions define new fields #1774

Merged
hansegucker merged 7 commits from feature/extensible-models into master 2020-01-19 11:31:28 +01:00
Owner

This MR extends the ExtensibleModel to accept fields in addition to properties and methods. It leverages django-jsonstore in order to aggregate those fields in one extended_data JSONField, so as to not need migrations when apps add additional fields. Apps should use this feature sparsely, and for more complex additions, add their own model with a ForeignKey instead.

The following example put in model_extensions.py of an app adds a field for the t-shirt size of a person:

from jsonstore import CharField

from .models import Person


Person.field(shirt_size=CharField(verbose_name="T-Shirt size", default="7XL"))

The fields are transparent to all known parts of Django. They are accessed like any other field, and even automagically show up in forms or a ModelAdmin:

Skjermdump_fra_2020-01-18_23-28-48

Filtering on JSONField is fully supported.

Advances #141.

This MR extends the `ExtensibleModel` to accept fields in addition to properties and methods. It leverages `django-jsonstore` in order to aggregate those fields in one `extended_data` `JSONField`, so as to not need migrations when apps add additional fields. Apps should use this feature sparsely, and for more complex additions, add their own model with a `ForeignKey` instead. The following example put in `model_extensions.py` of an app adds a field for the t-shirt size of a person: ``` from jsonstore import CharField from .models import Person Person.field(shirt_size=CharField(verbose_name="T-Shirt size", default="7XL")) ``` The fields are transparent to all known parts of Django. They are accessed like any other field, and even automagically show up in forms or a `ModelAdmin`: ![Skjermdump_fra_2020-01-18_23-28-48](/uploads/aadb0f56b3b0215f827c58e6644c8da2/Skjermdump_fra_2020-01-18_23-28-48.png) Filtering on `JSONField` is fully supported. Advances #141.
Author
Owner

changed milestone to %"2.0a1"

changed milestone to %"2.0a1"
Author
Owner

changed the description

changed the description
Author
Owner

added 1 commit

  • 445b1ca0 - Hide JSON field from forms and ModelAdmin by default

Compare with previous version

added 1 commit <ul><li>445b1ca0 - Hide JSON field from forms and ModelAdmin by default</li></ul> [Compare with previous version](/AlekSIS/AlekSIS/merge_requests/129/diffs?diff_id=1164&start_sha=7083b335f00aa8db460e7a92f8bfab480f09ea4b)
Author
Owner

added 1 commit

  • f041ec8d - Fix typo

Compare with previous version

added 1 commit <ul><li>f041ec8d - Fix typo</li></ul> [Compare with previous version](/AlekSIS/AlekSIS/merge_requests/129/diffs?diff_id=1165&start_sha=445b1ca0a528b1df23a5e4fecaaf9aed4ed9c9a8)
Author
Owner

added 1 commit

  • 9d866ef4 - Hide JSON field from forms and ModelAdmin by default

Compare with previous version

added 1 commit <ul><li>9d866ef4 - Hide JSON field from forms and ModelAdmin by default</li></ul> [Compare with previous version](/AlekSIS/AlekSIS/merge_requests/129/diffs?diff_id=1166&start_sha=f041ec8d0b361c457bbc2fd4a0ae8d9bf994e9fe)
Owner

mentioned in issue #158

mentioned in issue #158
Owner

merged

merged
Owner

mentioned in commit 79cb242b23

mentioned in commit 79cb242b2360987b27af97e735919b9d8639c625
Author
Owner

mentioned in issue AlekSIS#7

mentioned in issue AlekSIS#7
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aleksis/AlekSIS-Core!1774
No description provided.