#36024: model._meta.db_table
-------------------------------------+-------------------------------------
     Reporter:  ygbh                 |                     Type:
                                     |  Uncategorized
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  5.1                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 hello,use django ORM single
 run,exmaple:https://docs.djangoproject.com/en/5.1/topics/settings/#either-
 configure-or-django-settings-module-is-required
 set  db_table ref error.


 {{{
 class MyManager(models.Manager):
     _my_table_name = None

     def get_queryset(self):
         return super().get_queryset()

     def table_name(self, datetime_obj: Union[datetime, str]):
         if not self._my_table_name:
             MyManager._my_table_name = self.model._meta.db_table
         if isinstance(datetime_obj, datetime):
             self.model._meta.db_table: str = MyManager._my_table_name +
 '_' + datetime_obj.strftime('%Y_%m_%d')
         else:
             self.model._meta.db_table: str = MyManager._my_table_name +
 '_' + datetime_obj
         self.model._meta.verbose_name_raw = None
         return self
 }}}

 MySQLDB module print Query  SQL:

 {{{
 SELECT
         `record_gateway_2024_12_18`.`id`,
         `record_gateway_2024_12_18`.`label`,
         `record_gateway_2024_12_18`.`mobile`,
         `record_gateway_2024_12_18`.`nation_code`,
         CONCAT_WS( '', `record_gateway_2024_12_18`.`nation_code`,
 `record_gateway_2024_12_18`.`mobile` ) AS `phone`
 FROM
         `record_gateway_2024_12_17`
 WHERE
         CONCAT_WS( '', `record_gateway_2024_12_18`.`nation_code`,
 `record_gateway_2024_12_18`.`mobile` ) = '86110'
 ORDER BY
         `record_gateway_2024_12_18`.`recv_time` DESC
         LIMIT 1
 }}}

 **table_name is set success【record_gateway_2024_12_17】
 table_name ref var set fail【record_gateway_2024_12_18】**

 Running the Django project directly is normal.
 Django ORM has problems running alone.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36024>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070193d7877595-051c7d5b-420a-46fb-807e-542cfb4c7716-000000%40eu-central-1.amazonses.com.

Reply via email to