On Mon, 2009-02-23 at 16:54 +1100, Ryan Kelly wrote: > Hi All, > > > I'm currently working on an authentication backend that adds some > functionality to the standard one, and as part of this I want to modify > the behaviour of the User class. I've been subclassing auth.models.User > using standard model inheritance and it seems to be working fine. > > However, I don't need to add any fields to the User class, just > add/modify some methods. It seems like a waste to have an additional > database table created for my model subclass when it won't contain any > useful information. I briefly toyed with the idea of just > monkey-patching the User class, but figured there must be a better > way :-) > > So, is there a way to have a model subclass avoid the creation of a > new database table,and just take its data straight out of the table for > its superclass?
Not at the moment. I'd like to get that into Django, though. It's the missing "third" type of inheritance: Python-only. There's a ticket open in Trac (my internet connection is terrible at the moment, so I'm not going to hunt it out) that is to add an option to the Meta class saying "this model is not to be managed by Django". Primarily, that's for database views: you set them up outside of Django and syncdb won't create tables or anything like that. Turns out, that same option will work well for this case. If model B subclasses model A and model B says "Don't manage me", it should all just work fine. You will be able to add as much Python stuff to the model as you like and no database table will be created. Right now, I suspect you would also have to manually set Meta.db_table and some things like that. However, I strongly suspect each of those are fairly straightforward to sort out. We can set db_table automatically for such models, if it's not set. We have to make sure the pk property talks to the first ancestor model, too. Basically a bunch of fiddly stuff, but nothing that's brain surgery levels of difficulty. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---