views:

368

answers:

1

Is it possible to override the html naming of fields in TabularInline admin forms so they won't contain dashes?

I'm trying to apply the knowledge obtained here to create a TabularInline admin form that has the auto-complete feature.

It all works except that Django insists in naming the fields in a tabularinline queryset as something in the lines of:

[model]_set-[index]-[field]

So, if my model is TravelLogClient and my foreign key field is company, the fields in the HTML form for the three entries in the tabularinline queryset will be:

travellogclient_set-0-company
travellogclient_set-1-company
travellogclient_set-2-company

The problem is that javascript dislikes identifiers with dashes in them. So the javascript fails and the autocomplete doesn't work.

THIS IS ONLY A PROBLEM WITH TABULAR INLINE forms! If I use Jannis' autocomplete example on a non tabular admin form field, it works just fine because the field name doesn't have the "..._set-[index]-..." portion in the HTML and javascript.

Rather than submitting a patch to django's source code changing dashes for underscores on contrib.forms.forms.py and contrib.forms.formsets.py, it occurred to me that it is possible that behavior can be overridden somehow.

Failing that, what is the easiest way to make those dashes in the html_name become underscores instead?

Thanks in advance!

A: 

Paolo and Guðmundur are right. I modified my usage in the javascript according to Guðmundur's suggestion and things now work as expected - no django intervention needed.

Sorry for the mental lapse...

Thanks!

celopes