How to retrieve the app name from within my model declaration
In my application pos
, I have the following model::
class Receipt(Model):
class Meta:
db_table = 'pos_receipt'
I want to rename the table as pos_receipt_gh开发者_开发知识库ost
and I don't want to hardcode the app name.
I want to do this:
class Receipt(Model):
class Meta:
db_table = '%s_receipt_ghost` % get_app_name()
Does something like get_app_name
exists ?
Name of the app is available in Meta.app_label
class Receipt(Model):
class Meta:
pass
Receipt._meta.db_table = '%s_receipt_ghost' % Receipt._meta.app_label
Or
class Receipt(Model):
class Meta:
db_table = '%s_receipt_ghost'
Receipt._meta.db_table %= Receipt._meta.app_label
精彩评论