Skip to content

Varient faild Type Error when has GenericRelation #227

Open
@suxilog

Description

@suxilog

https://github.com/wagtail/wagtail-personalisation/blob/a81c5b35604ec6bfdab7a36474f9f4687a14f2e7/src/wagtail_personalisation/models.py#L273

Wagtail page model has exclude_fields_in_copy, but when personalisation create varient page, it does'n use this. We use hit count
as GenericRelation model, This through type error.
Our team use this way for temp:

def copy_for_segment(self, segment, exclude_fields=None):
        exclude_fields_in_copy = ["hit_count_generic"]
        default_exclude_fields_in_copy = ['id', 'path', 'depth', 'numchild', 'url_path', 'path', 'index_entries', 'comments']
        exclude_fields = default_exclude_fields_in_copy + exclude_fields_in_copy +(exclude_fields or [])
        page = self.canonical_page
        slug = "{}-{}".format(page.slug, segment.encoded_name())
        title = "{} ({})".format(page.title, segment.name)
        update_attrs = {
            'title': title,
            'slug': slug,
            'live': False,
        }

        with transaction.atomic():
            new_page = self.canonical_page.copy(
                update_attrs=update_attrs, copy_revisions=False, exclude_fields=exclude_fields)

            PersonalisablePageMetadata.objects.create(
                canonical_page=page,
                variant=new_page,
                segment=segment)
        return new_page

Same as page copy methord.
Will sent a PR later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions