Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to access ._meta directly in your django app?

Tags:

python

django

Django uses Meta class for lots of additional object information. However, they store this information in an object '_meta' which by naming convention is private.

All over the django admin (and other places) I see stuff like opts = model._meta and then they use the various options like app_label and verbose_name.

Can I be confident accessing ._meta and be sure that it will not change in the future, or am I better off creating one 'accessor' mixin or something that accesses the ._meta in one spot, so if it ever does change I only have to update one thing?

like image 307
Aaron Avatar asked Mar 18 '11 15:03

Aaron


1 Answers

I use _meta frequently and haven't had any issues so far. You can see in the django documentation an example of them using it too here, so I have felt its more or less ok to do. Just tread carefully and write good tests so you know of any problems when you upgrade your django version later on down the road.

like image 98
Jason Webb Avatar answered Sep 30 '22 20:09

Jason Webb