Python Forum
Upgraded Django, `AdminSplitDateTime` causes exception on `list` object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upgraded Django, `AdminSplitDateTime` causes exception on `list` object
#1
I'm upgrading a project from Python2.7 + Django1.8 to Python3.7 + Django3.1. The application contains a form using widget AdminSplitDateTime that displays a datetime attribute as two fields separately of date and time. This widget also splits one field into a list of two objects, and the default value is [None, None].

Root cause analysis:

I noticed that with Django1.8, function DateTimeField.to_python has a logic path to handle the list, see if isinstance(value, list): in the source code here.

However, the newer Django removed this handling, so result = parse_datetime(value.strip()) (see the source code here) triggers an exception AttributeError: 'list' object has no attribute 'strip'. At the triggering time, variable value was a list [None, None].

My questions: I want to keep the widget, or keep the two fields effect. Any hints will be highly appreciated.

Partial source code of my application:

class ProductAdminForm(BaseDynamicEntityForm):
    model = models.Product
    def _build_dynamic_fields(self):
        ...
        for attribute in self.entity.get_all_attributes()\
            .filter(producttemplateattribute__product_template=product_template):
            value = getattr(self.entity, attribute.slug)
            ...
            datatype = attribute.datatype
            ...
            elif datatype == attribute.TYPE_DATE:
                defaults.update({'widget': AdminSplitDateTime})
            ...
Reply


Messages In This Thread
Upgraded Django, `AdminSplitDateTime` causes exception on `list` object - by 1780yz - Feb-24-2021, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Django] Getting exception: "no such table: auth_user" SheeppOSU 3 5,734 Jul-11-2020, 06:06 AM
Last Post: SheeppOSU
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,451 Jun-30-2019, 12:21 AM
Last Post: scidam
  Django serve list-file foralobo 4 4,468 Oct-03-2017, 03:48 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020