Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to add a datetimefield to admin changelist's search_fields
    primarykey
    data
    text
    <p>In a model's changelist page on admin, I added a DateTimeField "birth" to search_fields.</p> <pre><code>class DataLog(models.Model): id = models.AutoField(primary_key=True, verbose_name="idd") birth = models.DateTimeField(auto_now_add=True, verbose_name="create_time") class DataLogAdmin(admin.ModelAdmin): search_fields = ['id', 'birth', ] </code></pre> <p>it works well when i add it. But a error comes out today:</p> <pre><code>Warning at /admin/data/log/ Incorrect datetime value: '%2011-07-12%' for column 'birth' at row 1 Django Version: 1.2.3 Exception Location: /usr/lib/python2.5/warnings.py in warn_explicit, line 102 </code></pre> <p>this is the db sql:</p> <pre><code>u'SELECT COUNT(*) FROM `data_log` WHERE (`data_log`.`id` LIKE %2011-07-12% OR `data_log`.`birth` LIKE %2011-07-12% )' </code></pre> <p>I'v edited my django's project a lot since then. </p> <p>so i dont know what cause this.</p> <p>here is my question:</p> <ul> <li>insert a DatetimeField to search_fields supported by django? </li> <li>what's the correct way to do this? </li> <li>any idea about my error?</li> </ul> <hr> <p><strong>New progress:</strong></p> <p>I tested that sql.</p> <p>In Mysql, it runs well. ( both mysql's commandline and Django's dbshell )</p> <pre><code>mysql&gt; SELECT COUNT(*) FROM `data_log` WHERE (`data_log`.`id` LIKE '%07-19%' OR `data_log`.`birth` LIKE '%07-19%' ); +----------+ | COUNT(*) | +----------+ | 3 | +----------+ 1 row in set, 1 warning (0.00 sec) </code></pre> <p>but in django shell, the same error:</p> <pre><code>User.objects.raw("SELECT COUNT(*) FROM `data_log` WHERE (`data_log`.`id` LIKE '%%07-19%%' OR `data_log`.`birth` LIKE '%%07-19%%' )")[0] Traceback (most recent call last): File "&lt;console&gt;", line 1, in &lt;module&gt; File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 1379, in __getitem__ return list(self)[k] File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 1372, in __iter__ for row in self.query: File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py", line 73, in __iter__ self._execute_query() File "/usr/lib/python2.5/site-packages/django/db/models/sql/query.py", line 87, in _execute_query self.cursor.execute(self.sql, self.params) File "/usr/lib/python2.5/site-packages/django/db/backends/util.py", line 15, in execute return self.cursor.execute(sql, params) File "/usr/lib/python2.5/site-packages/django/db/backends/mysql/base.py", line 86, in execute return self.cursor.execute(query, args) File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 168, in execute if not self._defer_warnings: self._warning_check() File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 82, in _warning_check warn(w[-1], self.Warning, 3) File "/usr/lib/python2.5/warnings.py", line 62, in warn globals) File "/usr/lib/python2.5/warnings.py", line 102, in warn_explicit raise message Warning: Incorrect datetime value: '%07-19%' for column 'birth' at row 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload