On Tue, Nov 20, 2012 at 4:35 AM, Russell Keith-Magee <russ...@keith-magee.com> wrote: > > On Tue, Nov 20, 2012 at 6:28 AM, Chris Cogdon <ch...@cogdon.org> wrote: >> >> Hi folks! >> >> I'm creating an application to manage an art show (with art pieces to view >> and sell, silent and voice auctions, and a sales process). To have this >> work, it of course needs to keep track of people (including names, >> addresses, email, etc). But to make this more useful to anyone, I want to >> include the ability to replace the included "Person" model with another, >> should the implementor so choose. >> >> What I've done so far is to split the Person model into another app >> (called Peeps) and removed all but a few necessary linkages between the >> Artshow and Peeps app. It was reasonably simple, but a few things seem >> "dirty" so I'm wondering if anyone else has a more experienced or >> authoritative suggestion for this. > > > Ok… so… In Django 1.5, yes there is… unofficially. > > Now - I must stress -- everything I'm about to say is 100% undocumented, and > 100% experimental. If it breaks, you get to keep all the shiny pieces :-) > I'm only mentioning it because I (personally) need people to experiment in > this space in order to prove to the core team that the feature is safe for > public consumption. > > With that caveat in place: > > In Django 1.5 (i.e., the current development branch), we've added the > ability to add swappable User models. This means you can replace Django's > builtin User model with any User model you want -- for example, a user model > that uses 'email' as the unique identifier, or one that captures API > credentials rather than first and last name. > > The dirty secret is that when I implemented this feature for contrib.auth, I > did so in a way that was completely independent of the User model itself. > There aren't any explicit references to contrib.auth in the main model code > that makes swappable User models possible. In theory *any* model can be > declared as swappable, which will allow the end user to define that in their > project the "X" model will be performed by model "Y", and any foreign keys > will be re-routed appropriately. > > The magic sauce: On the model you want to be swappable (Person, in your > case), add a Meta declaration: > > class Person(Model): > class Meta: > swappable = 'CUSTOM_PERSON_MODEL'
wow, I'm also taking notes of this :) -- Marc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.