copy page?

84 views
Skip to first unread message

Tom Scytale

unread,
Oct 10, 2012, 5:17:37 AM10/10/12
to django-...@googlegroups.com
Hi

I was looking for a way to copy a page. I don't see any way to do it via the admin interface (tho I am missing a handful of buttons due to a minor incompatibility with the version of grappelli i'm running).

I see a method Page.objects.create_copy() in 1.0.99 but it seems to have been removed in newer versions. 

I successfully copied a page by pasting the code from that method into the django shell.

Is the facility for copy a page really missing or am I being dumb?

thanks

Simon Meers

unread,
Oct 10, 2012, 5:39:37 AM10/10/12
to django-...@googlegroups.com
On 10 October 2012 20:17, Tom Scytale <scy...@gmail.com> wrote:
> I was looking for a way to copy a page. I don't see any way to do it via the
> admin interface (tho I am missing a handful of buttons due to a minor
> incompatibility with the version of grappelli i'm running).
>
> I see a method Page.objects.create_copy() in 1.0.99 but it seems to have
> been removed in newer versions.

It is recommended that you use Django's built-in admin save-as
functionality [1], however this is somewhat broken when it comes to
uploaded files etc [2,3,4], but works for simple cases. I'll be
working on a solution for this for a couple of projects in the coming
week or two.

Simon

[1] https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_as
[2] https://code.djangoproject.com/ticket/14760
[3] https://code.djangoproject.com/ticket/13223
[4] https://code.djangoproject.com/ticket/5681

Tom Scytale

unread,
Oct 10, 2012, 4:39:08 PM10/10/12
to django-...@googlegroups.com
On Wednesday, October 10, 2012 10:39:58 AM UTC+1, DrMeers wrote:
On 10 October 2012 20:17, Tom Scytale <scy...@gmail.com> wrote:
> I was looking for a way to copy a page. I don't see any way to do it via the
> admin interface (tho I am missing a handful of buttons due to a minor
> incompatibility with the version of grappelli i'm running).
>
> I see a method Page.objects.create_copy() in 1.0.99 but it seems to have
> been removed in newer versions.

It is recommended that you use Django's built-in admin save-as
functionality [1],

how do I use that? - It'll have to be something like this, right?

    from feincms.module.page.admin import PageAdmin
    from feincms.module.page.models import Page
    from django.contrib import admin

    class MyPageAdmin(PageAdmin):
            save_as = True

    admin.site.unregister(Page)
    admin.site.register(Page, MyPageAdmin)

And this will have to go into admin.py of some app that is listed in INSTALLED_APPS after feincms, right?

(I won't have the opportunity to try this for a few days but I'd like to check this is the right general direction)

t
       
however this is somewhat broken when it comes to
uploaded files etc [2,3,4], but works for simple cases.

 
I'll be working on a solution for this for a couple of projects in the coming
week or two.

that would be very useful

thanks

t

steffen....@magine.com

unread,
Sep 30, 2015, 5:52:39 AM9/30/15
to Django FeinCMS
Hi,

found a pretty easy way of doing this, that actually works:

in models.py


def duplicate_page(modeladmin, request, queryset):
   
from feincms.utils import copy_model_instance


   
for obj in queryset:
        copy
= copy_model_instance(obj)
        copy
.slug = 'copy-of-' + copy.slug
        copy
.title = 'Copy of ' + copy.title
        copy
.save()
        copy
.copy_content_from(obj)


duplicate_page
.short_description = "Duplicate all selected items"
PageAdmin.actions = [duplicate_page]

Best,
Steffen
Reply all
Reply to author
Forward
0 new messages