[Django] #36024: model._meta.db_table

24 views
Skip to first unread message

Django

unread,
Dec 17, 2024, 9:10:05 PM12/17/24
to django-...@googlegroups.com
#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.

Django

unread,
Dec 17, 2024, 9:14:41 PM12/17/24
to django-...@googlegroups.com
#36024: model._meta.db_table
-------------------------------------+-------------------------------------
Reporter: ygbh | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ygbh):

* type: Uncategorized => Bug

--
Ticket URL: <https://code.djangoproject.com/ticket/36024#comment:1>
Reply all
Reply to author
Forward
0 new messages