In the below models.py, the fields ‘EndDate & timestamp’ are causing problem.
Did migration successfully for the model ‘Dlist’.
Imported data to the table ‘Dlist’ including values for the newly created fields of EndDate and timestamp.
Now the forms which were working fine displaying all data, throws error. It took long time to understand the cause which happens because of these 2 date type and datetime type fileds.
The form worked fine with another model named ‘List’ which doesn’t have these 2 fields and all other data remains same.
Error
Django Version: 4.1
Exception Type: ValueError
Exception Value: invalid literal for int() with base 10: b'01/01/1900'
Exception Location: F:\Program Files\Python310\lib\sqlite3\dbapi2.py, line 64, in convert_date
Error during template rendering
In template F:\Program Files\Python310\lib\site-packages\django_tables2\templates\django_tables2\bootstrap4.html, error at line 26
invalid literal for int() with base 10: b'01/01/1900'
16 {{ column.header }}
17 {% endif %}
18 </th>
19 {% endfor %}
20 </tr>
21 </thead>
22 {% endif %}
23 {% endblock table.thead %}
24 {% block table.tbody %}
25 <tbody {{ table.attrs.tbody.as_html }}>
26 {% for row in table.paginated_rows %}
27 {% block table.tbody.row %}
28 <tr {{ row.attrs.as_html }}>
29 {% for column, cell in row.items %}
30 <td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
31 {% endfor %}
32 </tr>
33 {% endblock table.tbody.row %}
34 {% empty %}
35 {% if table.empty_text %}
36 {% block table.tbody.empty_text %}
Models.py
class Dlist(models.Model):
Name = models.CharField(max_length=100)
addr1 = models.CharField(max_length=100, blank=True, null=True)
addr2 = models.CharField(max_length=100, blank=True, null=True)
addr3 = models.CharField(max_length=100, blank=True, null=True)
............
EndDate = models.DateField(blank=True, null=True)
timestamp = models.DateTimeField(blank=True, null=True)
...
def __str__(self):
return str(self.id)
In the below view, if I use the model name ‘List’ the form displays all records as it is.
But if I change the view name to ‘Dlist’ then it is throwing error.
class ListTableView(SingleTableView):
table_class = ListTable
queryset = List.objects.defer(
'addr1',
'addr2',
'addr3',
).annotate(
Address=Concat(
'addr1',
'addr2',
'addr3',
'City',
'State', # Value(' - '),
str('Pincode'), output_field=CharField(),
),
)
template_name = "list_table.html"
Request help to use the new model ‘Dlist’ in place of ‘List’ - Thank you!