newbie needs to copy a record in admin to a new record

13 views
Skip to first unread message

frocco

unread,
Jan 11, 2013, 10:06:21 AM1/11/13
to django...@googlegroups.com
Hello,

I am just learning django and want to allow a user in admin to copy a record from the list to create a new record and make changes.
This will prevent having to type similar data.

How do I add a link to the admin list?
where do I put code to dup the record?

Thank you 

Brad Pitcher

unread,
Jan 11, 2013, 10:53:02 AM1/11/13
to django-users
I think what should work well for your use case is an admin action:

https://docs.djangoproject.com/en/1.4/ref/contrib/admin/actions/

You can write code for a copy action in admin.py. This will add a "copy" item to the dropdown in the list view, so you can select any number of list items and copy them.

---------
Brad Pitcher
Software Developer
(702)723-8255


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/odBD_lyCqmsJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

frocco

unread,
Jan 11, 2013, 11:07:03 AM1/11/13
to django...@googlegroups.com
Thank you

[code]
def make_copy(modeladmin, request, queryset):
    for obj in queryset:
        obj.pk = None
        obj.object_name = "dup"
        obj.save()
make_copy.short_description = "Copy selected records"
[/code]
Reply all
Reply to author
Forward
0 new messages