On Wed, Oct 9, 2013 at 6:16 AM, Burak Emre Kabakcı <[email protected]>wrote:

> It would be nice if you allow using two different models for
> django.contrib.auth module. The current User model is great for admin panel
> users but in frontend it may become extra overhead for some cases. People
> try to create another user attribute models and use extra joins to be able
> to keep extra attributes (city, ip, locale etc.) for their users.
>
> It seems there are a lot of improvements in Django 1.5 I think there are
> more thing that may be revised. For example I think we should be able to
> set AUTH_USER_MODEL setting per module basis or namespaced routes basis.
>
> In order to solve this issue I needed to create a middleware class to
> change settings.AUTH_USER_MODEL; however I know that this is not the ideal
> solution because in each request I need to re-set one of the static Django
> settings. Here is the middleware class:
>
> class ChangeBaseUser(object):
>     def process_request(self, request):
>         match = resolve(request.path)
>         if match.app_name == "myapp":
>             settings.AUTH_USER_MODEL = 'myapp.Customer'
>         else:
>             settings.AUTH_USER_MODEL = 'auth.User'
>
>  Hi Burak,

Thanks for the suggestion, but I think you need to think through the
consequences of this a little more. AUTH_USER_MODEL isn't just a setting --
it controls the way that foreign keys are constructed in the database. Once
a foreign key is constructed, it can't be (easily) pointed at a completely
different table. It *certainly* can't switch between tables on a
per-request basis.

It sounds to me that what you have is *two* different applications, using
two different user models. Those two applications might share a lot of
other logic, including models, views, and so on -- but that's why Django
promotes the idea of reusable apps. You can write two apps, deployed at two
different paths on the same domain, that share 95% of their logic, and only
vary on a small number of settings or additional apps - like an
AUTH_USER_MODEL setting.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAJxq848oaWHZ%2BCjJmiNYfh2uNi%2BqZs7ye_tje6%3D8sZAkSXZcCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to