Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Varient faild Type Error when has GenericRelation #227

Open
suxilog opened this issue Nov 12, 2021 · 0 comments
Open

Varient faild Type Error when has GenericRelation #227

suxilog opened this issue Nov 12, 2021 · 0 comments

Comments

@suxilog
Copy link

suxilog commented Nov 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant