Group Django model instances based on similar fields
- add
django_grouperto yourINSTALLED_APPS - add
path("", include("django_grouper.urls"))to yoururlpatterns - go to
/grouperand add the paramgroup_content_typeto specify which ContentType to group and the paramsgroup_fieldsto specify which fields to group by
If you define a GROUP_FILTER in you settings, the queryset in the /grouper view will be passed through this filter. The filter is expected to
be a callable and will receive the queryset and the request as parameters. This means you can pass the queryset together with the request to a
django-filter filter.
The /group view lets you select which objects of a list should be merged. If
you double click an object, it will become the primary, a single click marks an
object as secondary. There can be one primary and multiple secondaries. The
primary and the list of secondaries are then passed to the trigger_merge
signal. You can use this method to implement a custom merge method.
from django_grouper.signals import trigger_merge
@receiver(trigger_merge)
def react_on_merge_trigger(sender, primary, secondaries, **kwargs):
primary.merge(secondaries)