#3591: add support for custom app_label and verbose_name
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  adrian
  jkocherhans                        |         Status:  reopened
                   Type:  New        |      Component:  Core (Other)
  feature                            |       Severity:  Normal
              Milestone:  1.4        |       Keywords:
                Version:  SVN        |      Has patch:  1
             Resolution:             |    Needs tests:  0
           Triage Stage:  Fixed on   |  Easy pickings:  0
  a branch                           |
    Needs documentation:  0          |
Patch needs improvement:  0          |
                  UI/UX:  1          |
-------------------------------------+-------------------------------------

Comment (by bendavis78):

 Thanks.  For clarity's sake, I'm attaching a patch based on jezdez's app-
 loading branch that applies cleanly against r16630 (current svn trunk).  I
 also have this on my github fork here:
 https://github.com/savidworks/django/tree/app-loading.

 Also, for the benefit of others interested in this patch, I'll do my best
 to explain what it does based on what I've gleaned from the source:

 ----

 The ```INSTALLED_APPS``` setting may now contain a reference to an
 ```App``` class. For example:

 {{{#!python
 INSTALLED_APPS = (
     # ...
     'django.contrib.admin',
     'myapp.apps.MyApp',
 )
 }}}

 These app classes extend ```django.apps.App```, and may define a number of
 properties:
 {{{#!python
 from django.apps import App

 class MyApp(App):
     class Meta:
         verbose_name = 'My sweet pony app'
 }}}

 Other properties that can be set on Meta are ```db_prefix``` and
 ```models_path```.  This will allow you to override existing app
 definitions in order to prevent potential conflicts.

 When the app loader loops through ```INSTALLED_APPS```, it converts any
 normal modules an ```App``` class and loads everything into the apps cache
 (which was moved from ```django.models.loading``` to
 ```django.apps.cache```).  This cache is, among other things, used by the
 admin for introspection of apps and models.

 For further customization, one may also specify how an ```App``` class is
 initialized by providing kwargs in the ```INSTALLED_APPS``` setting:
 {{{#!python
 INSTALLED_APPS = (
     # ...
     ('myapp.apps.MyApp', {'verbose_name':'Something else','foo':'bar'}),
 )
 }}}

 In this case, ```MyApp``` would be initialized to the equivalent of:
 {{{#!python
 class MyApp(App):
     foo = 'bar'
     class Meta:
         verbose_name = 'Something else'
 }}}

 ----

 My only question at this point is regarding the design decision to use an
 options class (ie, ```MyApp.Meta```).  The code suggests that other
 properties may be set on your custom App class, but how might one use
 custom properties on an App class?  I'm sure there's a reason for not
 putting verbose_name, db_prefix, and models_path in the class's main
 properties, I'm just curious what the thinking is on that.

 On another note, I was thinking it would also be useful to allow app
 authors to define how apps should be displayed to the end user.
 Specifically, I think it would be nice to be able to group and order
 models in a way that would be more meaningful or helpful to admin users.
 Perhaps that's one thing that could be done on within a custom App class.
 Although, that might be a discussion for another time.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/3591#comment:109>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to