Add ability to extend exclude_fields for use when copying page
See original GitHub issueIssue Summary
If your Page model contains relations that do not use ClusterableModel
you cannot copy those pages in admin without causing an error. Adding the ability to define what fields must be excluded on copy per Page would enable working around this.
Steps to Reproduce
Note: This is my specific use case.
- Start a new Wagtail project
- Install Django Activity Stream http://django-activity-stream.readthedocs.io/en/latest/
pip install django-activity-stream
- In your main
apps.py
register a generic link to your Page modelregistry.register(Page)
- http://django-activity-stream.readthedocs.io/en/latest/configuration.html - Open a Page list in Admin and click More > Copy
- Change the Slug to something Unique
- Click ‘Copy this Page’
This results in the following Error: TypeError: ‘GenericRelatedObjectManager’ object is not iterable
The trace error is:
[09/Oct/2017 09:29:35] ERROR [django.request:135] Internal Server Error: /admin/pages/233/copy/
Traceback (most recent call last):
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 43, in _cache_controlled
response = viewfunc(request, *args, **kw)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/decorators.py", line 31, in decorated_view
return view_func(request, *args, **kwargs)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/utils.py", line 140, in wrapped_view_func
return view_func(request, *args, **kwargs)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/views/pages.py", line 837, in copy
user=request.user,
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailcore/models.py", line 1116, in copy
page_copy = self.specific_class(**specific_dict)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailcore/models.py", line 376, in __init__
super(Page, self).__init__(*args, **kwargs)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/modelcluster/models.py", line 177, in __init__
super(ClusterableModel, self).__init__(*args, **kwargs)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 567, in __init__
_setattr(self, prop, kwargs[prop])
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/db/models/fields/related_descriptors.py", line 537, in __set__
manager.set(value)
File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 613, in set
objs = tuple(objs)
TypeError: 'GenericRelatedObjectManager' object is not iterable
Proposed Solution
- The line above:
exclude_fields = ['id', 'path', 'depth', 'numchild', 'url_path', 'path']
- Could be replaced with something like:
self.excluded_fields_for_copy
- The default would be the list above but this could be extended for a specific class like:
excluded_fields_for_copy = Page.excluded_fields_for_copy + ['action_object_actions', 'actor_actions', 'target_actions']
- As this is different to the
exclude_fields
used inmodelAdmin
it would need to be named specifically in relation to copying.
Technical details
- Python 2.7.12
- Django v.1.11.5
- Wagtail v.1.12.2
- Browser version: Chrome 61 on OS X 10.12.6
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to add/exclude fields to a form that extends another form
So I want to add date_of_birth to AnotherUserCreationForm and at the same time, I want to exclude role and is_staff in ...
Read more >Add ability to exclude translatable fields from being handled ...
An entity may contain fields that hold data they are strictly for layout or presentation purposes.
Read more >Exclude a table from cloning
The System Clone > Exclude Tables module lists the tables that are not copied during a system clone. By default, the system excludes...
Read more >Copy and paste specific cell contents - Microsoft Support
Reorients the content of copied cells when pasting. Data in rows is pasted into columns and vice versa. Paste Values. Only the values...
Read more >Mail merge: Edit recipients - Microsoft Support
The list of recipients Shows all the records that will be used in your mail merge. · Data Source Select Edit to change...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gasman I will give a go at implementing this for a pull request next week.
Just hit this issue myself, the error message given doesn’t make it clear what’s going on. So I wonder if it’s worth excluding generic relations by default?