views:

52

answers:

2

What is the best approach to extending the Site model in django? Creating a new model and ForeignKey the Site or there another approach that allows me to subclass the Site model?

I prefer subclassing, because relationally I'm more comfortable, but I'm concerned for the impact it will have with the built-in Admin.

+1  A: 

I just used my own subclass of Site and created a custom admin for it.

Basically, when you subclass a model in django it creates FK pointing to parent model and allows to access parent model's fields transparently- the same way you'd access parent class attributes in pyhon. Built in admin won't suffer in any way, but you'll have to un-register Sites ModelAdmin and register your own ModelAdmin.

fest
What about these things? Do they still work?http://docs.djangoproject.com/en/dev/ref/contrib/sites/#how-django-uses-the-sites-framework
rebus
+1  A: 

If you only want to change behaviour of the object, but not add any new fields, you should consider using a "proxy model" (new in Django 1.1). You can add extra Python methods to existing models, and more:

This is what proxy model inheritance is for: creating a proxy for the original model. You can create, delete and update instances of the proxy model and all the data will be saved as if you were using the original (non-proxied) model. The difference is that you can change things like the default model ordering or the default manager in the proxy, without having to alter the original.

Read more in the documentation.

Justin Voss
I'm looking to add new field; but thanks for the information. Very useful regardless.
John Giotta