Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:23:42+00:00 2026-05-24T19:23:42+00:00

In a model’s changelist page on admin, I added a DateTimeField birth to search_fields.

  • 0

In a model’s changelist page on admin, I added a DateTimeField “birth” to search_fields.

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', ]

it works well when i add it. But a error comes out today:

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

this is the db sql:

u'SELECT COUNT(*) FROM `data_log` WHERE (`data_log`.`id` LIKE %2011-07-12% OR `data_log`.`birth` LIKE %2011-07-12% )'

I’v edited my django’s project a lot since then.

so i dont know what cause this.

here is my question:

  • insert a DatetimeField to search_fields supported by django?
  • what’s the correct way to do this?
  • any idea about my error?

New progress:

I tested that sql.

In Mysql, it runs well. ( both mysql’s commandline and Django’s dbshell )

mysql> 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)

but in django shell, the same error:

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 "<console>", line 1, in <module>
 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:23:43+00:00Added an answer on May 24, 2026 at 7:23 pm

    ok… I found the answer myself.

        Warning: Incorrect datetime value: '%123%' for column 'birth' at row 1
    
    • In mysql, using LIKE for datetime field works, but not Recommend. So, there is always the warning above. http://bugs.mysql.com/bug.php?id=38915

    • In Django, if we set “Debug=True” in settings.py, django handle this warning as an error.

    so, all searches for that model fail.

    I’ll keep that DateTimeField in search_fields, but only used in non-Debug servers.


    For my original question in title, the answer is:

    • just add DateTimeField to search_fields, it works for non-Debug servers
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My model is: class Report(models.Model): created = models.DateTimeField(auto_now_add=True) My views is: def filter_range(request): results
#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def
Model: class Subject(models.Model): name = models.CharField(max_length=100) slug = models.SlugField(unique=True) description = models.TextField(blank=True,null=True) Forms: class
model: class Store(models.Model): name = models.CharField(max_length = 20) class Admin: pass def __unicode__(self): return
Model: class ExpertLevel(models.Model): level = models.CharField(max_length=100) subject = models.ManyToManyField(Subject, blank=True, null=True) class Expert(models.Model): appuser
model: class Province(models.Model): user = models.ManyToManyField(User, blank=True) name = models.CharField(max_length=30, unique=True) class City(models.Model): name
My model definition: class Thing1(models.Model): thing2s = models.ManyToManyField(Thing2, blank=True) I have an instance of
Model and ModelForm in django project are defined like this : class Consumption(models.Model): date=models.DateTimeField(default=datetime.now)
model.py: class Tribes(Group): members = models.ManyToManyField(User, related_name='tribes', verbose_name=_('members')) i want to store a number
My model is like this class Foo(models.Model): user = models.ForeignKey(User) class Meta: abstract =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.