I

On May 6, 1:05 pm, Thomas Weholt <thomas.weh...@gmail.com> wrote:
> I've inlined a model so that when I add a new object of the parent
> model ( for the inlined model ) I can add child model instances in the
> same form, all done in admin.py. Standard stuff actually. But each
> child object has a sort_order-field with default value = 1. I'd like
> to have that default value reflect what order the inlined model is in
> the parents form. Say I add a new parent, in my form for adding a
> parent in the admin, I automatically get three inlined child items I
> can add if I want, each exposing a sort_order field with the value 1.
> I want those inlined models to get sort_order = 1, 2 and 3. If I click
> to add a new child item in that same form, it should be giving
> sort_order = 4, then 5 etc. You get the picture?
>
> Is this possible?
>
> --
> Mvh/Best regards,
> Thomas Weholthttp://www.weholt.org

I think the easiest way to do this would be to override the admin
template,
adding some JS which populates the sort order field on page load and
after a new child row is added.

Your template would need to extend the extrahead block in
django/contrib/admin/templates/admin/change_form.html

Another option could be to extend InlineModelAdmin so you can pass
initial data to the inlineformset_factory, but without testing I'm not
sure
if this is possible.

Mike

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

Reply via email to