Delegate mixins' model fetch to a method #208

Closed
danfairs opened this Issue May 15, 2012 · 4 comments

2 participants

@danfairs

Currently, all the classes in mixins.py use self.resource.model to get a model class, where resource is itself a class.

I'd like to be able to customise the model that's returned per-request. Having a get_model() (or model_class(), or whatever) method on ModelMixin would make this a lot easier. Its default implementation could simply be to return self.resource.model.

My motivation for this is a multi-tenant system, where there are sets of very similar models, but with small modifications per-tenant. They're similar enough to share Resource implementations; but it's very hard to plug them in at the moment without overriding the whole of get(), post() etc. Pulling that logic out into a method would make that much easier to override.

I can spend some time implementing this if you think it's a good change; otherwise, I'll maintain the overrides in our own application.

@danfairs

One further comment - this is pretty similar to get_form_class() on FormResource.

@tomchristie
Owner

Hi Dan,

Both of these seem like good pull reqs to me. I think it might be worth hanging back tho. I'm trying to get around to a big refresh, which'll involve a new version based on the 'develop' branch here, and the work in django-serializers. I'm kind of freezing work on the current version until I've got that done.

@danfairs

OK - fair enough! We can keep the changes in our application until then. Thanks for taking the time to look at it!

@tomchristie
Owner

REST framework 2 mixins use the standard '.get_object()' and '.get_queryset()' methods as provided by Django's Generic CBVs. I think that adequately addresses this ticket, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment