If anyone is interested in this question, I have fixed this myself, with
approach number 2.
I had to copy two js files from django to my project and then fix that
files.
вторник, 19 апреля 2016 г., 15:02:30 UTC+3 пользователь Константин Попов
написал:
>
> Hi, django users.
>
> I have found possible bug in django admin site, using tabular inline with
> datetime field. The same bug exists in stacked inline as I can see form
> code.
>
> I am not sure what is the best way to report the bug, so I decided to
> write here first.
> Please, give me advice on my next steps.
>
> Now, about the bug.
>
> Any datetime field is supplied with calendar and clock
> shortcuts. static/admin/js/admin/DateTimeShortcuts.js contains code, wich
> generated all html markup for them, this code runs on page load event.
> This code makes both span class="datetimeshortcuts" and hidden div
> class="calendarbox module" or class="clockbox module".
>
> TabularFormset and stackedFormset jquery plugins, that live
> in static/admin/js/inlines.js, both need to reinit datetime fields in the
> newly added formset rows.
> They do it with this function:
>
> var reinitDateTimeShortCuts = function() {
>
> // Reinitialize the calendar and clock widgets by force, yuck.
> if (typeof DateTimeShortcuts !== "undefined") {
> $(".datetimeshortcuts").remove();
> DateTimeShortcuts.init();
> }
>
> };
>
>
> As anyone can see, this function removes datetimeshortcuts spans but doesn't
> remove "calendarbox module" and clockbox module" divs.
>
> Then, call to the DateTimeShortcuts.init() again and again adds both the
> spans and the divs for all datetime fields on the page.
>
>
> Thus, by adding 20 rows in formset, I have about 400 useless hidden divs on
> my page.
>
>
>
> I see several ways to fix this bug.
>
>
> 1. Modify DateTimeShortcuts.js to use single hidden div for all datetime
> fields on the page
>
> 2. Modify DateTimeShortcuts.js init function to check if the datetime field
> is alreay initialized to avoid it's re-initialization, and exclude removing
> any DOM elements from reinitDateTimeShortCuts
>
> 3. Expand set of elements, removed in reinitDateTimeShortCuts and remove divs
> together with spans. Maybe it would be better to add reinit function into
> DateTimeShortcuts.js
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/449afd1f-3c16-490a-a9fe-d3a73c1fa409%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.