Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing django user authentication & taggit for multiple apps in a single project
    primarykey
    data
    text
    <p><strong>Background:</strong> I have 5 independent Django projects which I am attempting to combine in to 1 Django project composed of several apps. In other words: projA has appA, projB has appB &amp; projC has appC, etc. I want 1 masterProj that has appA, appB &amp; appC.</p> <p>Currently each app connects to it's own independent database (the apps don't share data). Each project uses Django user authentication, Django registration, taggit, profiles, comments and sorl-thumbnail.</p> <p>I'm using Django 1.4 and setup <a href="https://stackoverflow.com/questions/3637419/multiple-database-config-in-django-1-2">database routing according to this stackoverflow answer</a> so that, once combined into one project, each app in the newly combined Django project is still able to connect to its own database. That went smoothly, but I started running into trouble with things like user authentication and taggit:</p> <p><strong>1)</strong> As mentioned before, each app connects to a different database and each of those databases has a table named 'auth_user'. However, I've found that all read/write calls to the auth_user table (regardless of which app makes the read/write call) are routed to the default database (in this case appA's database):</p> <pre><code># settings.py: DATABASES['default'] = DATABASES['appA'] DATABASE_ROUTERS = ['appA.db.DBRouter', 'appB.db.DBRouter', 'appC.db.DBRouter'] # appA/dbrouterA.py (appB, appC routers are identical this, replacing 'appA' with 'appB', etc.) class DBRouter(object): def db_for_read(self, model, **hints): if model._meta.app_label == 'appA': return 'appA' if model._meta.app_label == 'auth': return 'appA' return None def db_for_write(self, model, **hints): if model._meta.app_label == 'appA': return 'appA' if model._meta.app_label == 'auth': return 'appA' return None </code></pre> <p><strong>2)</strong> <em>Assuming I get the routing working, if a user logs into appA, I don't want them to be logged into appB</em>. I have seen many people post the reverse question (they want their apps to share user credentials) but has anyone successfully used Django user authentication in several independent apps in the same project? If so, how did you do this?</p> <p><strong>3)</strong> I get the following error from my taggit code, but I haven't been able to figure out how to pass the "related_name" parameter to taggit. I'm using the basic implementation of taggit - not subclassing anything:</p> <pre><code># appA/models.py tags = TaggableManager(blank=True) # appB/models.py tags = TaggableManager(blank=True) </code></pre> <p>Error:</p> <pre><code>appA.userprofile: Accessor for m2m field 'tagged_items' clashes with related m2m field 'TaggedItem.userprofile_set'. Add a related_name argument to the definition for 'tagged_items'. appB.userprofile: Accessor for m2m field 'tagged_items' clashes with related m2m field 'TaggedItem.userprofile_set'. Add a related_name argument to the definition for 'tagged_items'. </code></pre> <p><strong>4)</strong> I'm starting to get the feeling that combining all these apps is a slippery slope; that later down the line I might run into problems with sorl-thumbnail or comments that haven't surfaced yet. Has anyone successfully combined apps into a single project? Or am I trying to do something that Django doesn't fundamentally support?</p> <p>Thanks in advance for the help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COWhy do you want to combine them? It sounds to me that you actually want to keep them separate -- even the auth table is not shared. Anyhow, you'd have to at least build a new authentication backend that actually uses `using()` in the get call as well as a session handler that knows which app you're logged into... My gut tells me this is very unexplored territory. Good luck!
      singulars
    2. COMy end goal is to consolidate the apps (meaning 1 Django project with 1 app; currently a lot of the apps share common code). But as a first step I thought I would combine them all into 1 project; however, this is getting much tougher than I thought. Thanks for the info!
      singulars
    3. COhmm interesting. Perhaps you could start to tackle that project by dealing with authentication in the default database as it would be in the final combined product? Your code would not have to change from the intermediary stage (5 app) to the final (1 app) when you combine databases if you come up with a auth interface that would handle separate logins for different sections of the site! Also one tip: you would probably get more help if you separate your auth question from your taggit question.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload