#10356: proxy models:  subclassing models without create a new table
---------------------------+------------------------------------------------
 Reporter:  rfk            |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Uncategorized  |     Version:  1.0       
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 Following a discussion with Malcolm on django-users, I've implemented
 support for what's tentatively named "proxy models".  These provide a way
 for model subclasses to modify the behaviour of a model without creating a
 new database table.  The canonical example seems to be subclassing the
 User model - you might want to add additional methods/managers/etc, but
 you still want to pull data directly from the main users table.  Under the
 attached patch this would look like the following:

 {{{
     class MyUser(User)
         def extra_method(self):
             print "I am a new method"
         class Meta:
             proxy = True
 }}}

 MyUser is now simply a different view onto the main User table, rather
 than a full-blown subclass with a separate table.

 The main body of the patch is to db/models/base.py, where the meta
 attributes of proxy models are automatically set up.  Since it's now
 possible for a model to be using the same (table,primary key) pair as one
 of its base classes, I've added a small optimisation in
 db/models/sql/query.py that avoids a needless join in this case.  There's
 also some tests and a first stab at some documentation.

 This patch also integrates with (but doesn't require) ticket #3163, by
 marking proxy models as unmanaged.

 The django-users discussion leading to this patch can be found here:
 http://groups.google.com/group/django-
 users/browse_thread/thread/fb06ff8e2a296f9c

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10356>
Django <http://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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to