Removing a SourceColumn

Questions, comments, discussions. Over time certain topics might be moved to their own category.
Post Reply
lsmoker
Posts: 37
Joined: Wed Sep 05, 2018 3:52 pm

Removing a SourceColumn

Post by lsmoker »

Is there a way to remove SourceColumns? I've added some, but I'd also like to remove mimetype and encoding from the DocumentFile view.
---
LeVon Smoker
User avatar
michael
Developer
Developer
Posts: 266
Joined: Sun Apr 19, 2020 6:21 am

Re: Removing a SourceColumn

Post by michael »

That functionality is being added to the navigation classes but its not documented and not complete. Eventually all SourceColumn instances will have a 'name' attribute to be able to reference them independently and removed.

Example from events/apps.py

Code: Select all

        SourceColumn(
            attribute='timestamp', is_identifier=True,
            is_sortable=True, label=_('Date and time'), name='timestamp',
            source=Action
        )
For now what we do in some custom apps is iterate over the SourceColumns of a source object, match the attribute and remove that SourceColumn from the list of source object columns.

This example removes the creation date and time columns from the recently created document proxy model.

Code: Select all

source_columns = SourceColumn._registry.get(RecentlyCreatedDocument, ())
for source_column in source_columns:
    if source_column.attribute == 'datetime_created':
        source_columns.remove(source_column)
lsmoker
Posts: 37
Joined: Wed Sep 05, 2018 3:52 pm

Re: Removing a SourceColumn

Post by lsmoker »

Thanks for this!
---
LeVon Smoker
Post Reply