I have an object LeatherChair
in Django, and it pisses me off that Django gives it an object_name
of leatherchair
. I want it to be leather_chair
, with an underscore.
The object_name
seems to be stored in the Options
instance, but how do I change that?
Trying to change object_name
is a really bad idea. It is set in the Model._meta
as you say, but it is not one of the documented available Meta options. Trying to change it risks breaking stuff.
I don't understand why it is so important to change it. It's not displayed publicly, so it doesn't really matter whether it has an underscore or not. In the comment below you point out that object_name
is used by the CBV, but I would use the documented ways to change context_object_name
in the CBV instead of trying to change it on the model
If you must change it on the model, you probably need to hack around in django.db.models.options
. You could try monkey patching DEFAULT_PARAMS
, to allow you to set object_name
in the model Meta
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With