effective adding records in Django site admin

25 views
Skip to first unread message

vev...@yandex.ru

unread,
Oct 4, 2011, 1:01:06 AM10/4/11
to Django users
Good morning!
Could you tell me, is there any solution to add several records?
1) Now we can click Add, this gives us an empty version of the edit
page. I believe it is comfortable to have a Copy button, clicking Copy
would give us a page with a copy of a previuosly selected record, we
could edit several fields in it and save a new record.
2) One more comfortable tool, I believe, would be 2-dimensional form
for group addings records: rows corresponds to one field, columns to
another, cells to third. Saving such a form would create several
records, one for every filled cell.
May be such solutions are exist ? If not, could you give me any
advice?
Thank you very much!

Ilian Iliev

unread,
Oct 4, 2011, 4:02:49 AM10/4/11
to django...@googlegroups.com
Hi,

you can always create custom admin page for your models by extending
the default admin.


--
eng. Ilian Iliev
Web Software Developer

Mobile: +359 88 66 08 400
Website: http://ilian.i-n-i.org



--
You received this message because you are subscribed to the Google Groups "Django users" group.
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.


Thomas Orozco

unread,
Oct 4, 2011, 5:01:07 AM10/4/11
to django...@googlegroups.com

Regarding your first question, the admin save_as field does exactly this.

Le 4 oct. 2011 07:01, "vev...@yandex.ru" <vev...@yandex.ru> a écrit :

vev...@yandex.ru

unread,
Oct 5, 2011, 3:08:26 AM10/5/11
to Django users
Thank You very much! Adding option "save_as = True" to ModelAdmin
subclass is exactly what I need.

On 4 окт, 13:01, Thomas Orozco <g.orozco.tho...@gmail.com> wrote:
> Regarding your first question, the admin save_as field does exactly this.
> Le 4 oct. 2011 07:01, "veva...@yandex.ru" <veva...@yandex.ru> a écrit :

vev...@yandex.ru

unread,
Oct 5, 2011, 3:14:57 AM10/5/11
to Django users
Thank You very much! Tell me please what directory is to be used to
place such extensions

shacker

unread,
Oct 5, 2011, 11:52:16 AM10/5/11
to django...@googlegroups.com
If you want the ability to make copies of multiple records at once, or just want the "copy" option to appear at the top of the object list instead of having to click through into each record, it's pretty easy to set up an Admin Action. Here's one I use in a system that lets staffers duplicate Course records from one semester to another.  In admin.py:

# Custom Admin Action enables making a complete copy of a course (like a Save As...)
def make_copy(modeladmin, request, queryset):
    for obj in queryset:
        # Make a copy in memory
        # Override the ID so the db can auto_increment -- otherwise we overwrite the original!
        # Update the title of the new object
        n = obj
        n.id = None
        n.title = "NEW COPY OF: " + obj.title 
        n.save()
        request.user.message_set.create(message="Selected courses have been copied. Remember to set their Instructors and Programs!")
make_copy.short_description = "Make copies of selected courses"

.....

                
class CourseAdmin(admin.ModelAdmin):
    list_display = ('jstring','title', 'ccn', 'semester')
    search_fields = ('title','jstring__name')
    actions = [make_copy]
    form = CourseAdminForm
Reply all
Reply to author
Forward
0 new messages