Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing django user authentication & taggit for multiple apps in a single project
    text
    copied!<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>
 

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