Is it possible to write generic module?

16 views
Skip to first unread message

Det S. Pillner

unread,
Mar 27, 2017, 8:41:28 AM3/27/17
to Django users
Hi all,

I work on tools for my job based on Django 1.8.17. In different projects (with different databases) I use same routine to get some data (config data). My problem is: the way is every time the same: import model, get config data from database. The difference is: model name is in every database different.

My question: Can I transfer source table name in kwargs params, import this table and get data? My test means no: table name is ever interpreted as string. And string has no object property...


Avraham Serour

unread,
Mar 27, 2017, 9:00:58 AM3/27/17
to django-users
yes, table name can a parameter to your function

what do you mean by "import this table"?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/674a3571-b6b5-4da4-a8ce-0f918e1fe308%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Melvyn Sopacua

unread,
Mar 27, 2017, 9:45:06 AM3/27/17
to django...@googlegroups.com

On Monday 27 March 2017 05:41:28 Det S. Pillner wrote:

 

> I work on tools for my job based on Django 1.8.17. In different

> projects (with different databases) I use same routine to get some

> data (config data). My problem is: the way is every time the same:

> import model, get config data from database. The difference is: model

> name is in every database different.

 

Django has a settings framework.

Mezzanine has built on that to make settings stored in database *and* support multitenancy through the django.contrib.sites framework and supports per-app defaults for free.

 

Why would you need yet another way?

--

Melvyn Sopacua

Det S. Pillner

unread,
Mar 28, 2017, 12:55:52 AM3/28/17
to Django users
Hi,

many thanks. Your phrase 'yes, table name can a parameter to your function' fix my problem. I send table object (import in calling module - means: from app.models.tool import *) to my module. It works. So, import in config module is not required.

You are the greatest.


On Monday, March 27, 2017 at 3:00:58 PM UTC+2, Avraham Serour wrote:
yes, table name can a parameter to your function

what do you mean by "import this table"?
On Mon, Mar 27, 2017 at 3:41 PM, Det S. Pillner <silve...@gmail.com> wrote:
Hi all,

I work on tools for my job based on Django 1.8.17. In different projects (with different databases) I use same routine to get some data (config data). My problem is: the way is every time the same: import model, get config data from database. The difference is: model name is in every database different.

My question: Can I transfer source table name in kwargs params, import this table and get data? My test means no: table name is ever interpreted as string. And string has no object property...


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages