Managing objects spred among several tables/databases.

41 views
Skip to first unread message

qMax

unread,
Jun 30, 2011, 12:23:22 AM6/30/11
to Django users
Hello here.

My application task is to integrate several applications, and it
should manipulate objects, spread among several tables in several
databases. Final object is constructed by 'joining' tables by single
field (or derivatives).
A user should see such objects as solid entities and manipulate them
with basic CRUD operations (with search).
Backend should synchronize all changes in all databases.
And i wish i could use admin site for that.

If i guess correctly, all required magic should go into custom
QuerySet implementation to properly translate CRUD operations on
models into various distributed requests on databases, like zigzag-
joins, etc instead of usual sql.Queries.

I wonder if QuerySet is the only consolidation of such interface.
What else should i customize to make it work? (i see at least
db.models.Manager should be customized to use another queryset impl)
Also, how to figure out what subset of QuerySet interface is used in
admin site?

Maybe, someone already managed similar task and there are some recipes?
Message has been deleted

Hummingbird

unread,
Jul 2, 2011, 1:39:11 AM7/2/11
to Django users
Hi !
I have a similar situation.
(disclaimer:-- I have tried turbogears & web2py before.
But could not find the following functionality there.
So I have signed-in here to see whether I can get it in django).

My form is composed of fields from various tables.
When a user interacts with form, he/she may add/edit/delete/keep
unchanged certain fields,
After saving the form, I need to understand---
1) which table(s) should receive SQL add statement,
2) which one(s) need update stmt,
3) which one(s) to receive delete stmt.

Some examples of (desktop) frameworks having this feature:--
i) CursorAdaptor in VFP
ii) DABO desktop framework
But I am looking for a web framework having this feature.

Without a proper method (rather class) to handle it, it would be very
messy.
There will be code repetitions, etc.

I am eager to know whether there is any facility to do the above thing
in django.
In that case, I will happily switch to django.
Any comments/advise/knowledge-sharing highly appreciated.

Thanks.

Hummingbird

unread,
Jul 5, 2011, 12:28:36 PM7/5/11
to Django users
Can anybody pl. share his/her experience on this issue?
Thanks.
> > Maybe, someone already managed similar task and there are some recipes?- Hide quoted text -
>
> - Show quoted text -

Hummingbird

unread,
Jul 8, 2011, 9:19:42 AM7/8/11
to Django users
Not to put too fine a point on this.
I was hopeful to get some reply on this list (I heard that django
community is superbly active).
But it seems that either this post of mine alongwith "qMax" (OP) was
extremely silly,
OR
Nobody understood the gravity of our post.
In data-centric business apps (not like Yet Another Blog or Movie
Upload), such complexities as we mention in the above post, are a
regular part of life.

Regards,
Vineet
> > - Show quoted text -- Hide quoted text -

Cal Leeming [Simplicity Media Ltd]

unread,
Jul 8, 2011, 9:38:22 AM7/8/11
to django...@googlegroups.com
Hummingbird,

If there is no reply to a question, it's either because people are
busy, no one knows the answer, or because the OP did not make any
sense. Personally, I read the post and thought "this post makes no
sense". OP may want to re-phrase their original post in the form of a
real set of questions. If in doubt, please refer to the following
document:

https://code.djangoproject.com/wiki/UsingTheMailingList

In regards to your comment of "Nobody understood the gravity of our
post", I refer you to the following line in the above document:

Don't expect an instant or one-shot answer. (django-users is *NOT*
your personal tutor.)

Cal

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

Hummingbird

unread,
Jul 8, 2011, 11:01:31 AM7/8/11
to Django users
@Cal,
My apologies if my post has hurted you.
I didn't mean that.
I understand that all these open source projects are run by people who
don't get paid for it.

My point was quite different. It was about knowledge sharing.
We can re-phrase the question if nobody understands what we mean to
ask.
Actually, we are not asking for any exact code or any spoon-feeding.
We are asking whether anybody has developed a solution similar to
CursorAdaptor in VFP
Ed Leafe & Paul McNett have done marvelous work in this area (DABO
desktop framework).

Instead of making this post very long by giving details of what is a
CursorAdaptor, pl. refer to --
http://msdn.microsoft.com/en-us/library/d993hde7(v=vs.80).aspx

Regarding your remark of "Don't expect an instant answer"--
-- OP was dated 30th June.
Today is 8th July (an instant???)

Again, pl. excuse me if I have said anything wrong.
@qMax: Have you got any way around your question?

---Vineet

On Jul 8, 6:38 pm, "Cal Leeming [Simplicity Media Ltd]"

Cal Leeming [Simplicity Media Ltd]

unread,
Jul 8, 2011, 11:19:07 AM7/8/11
to django...@googlegroups.com
On Fri, Jul 8, 2011 at 4:01 PM, Hummingbird <vineet....@gmail.com> wrote:
@Cal,
My apologies if my post has hurted you.
I didn't mean that.
I understand that all these open source projects are run by people who
don't get paid for it.

My point was quite different. It was about knowledge sharing.
We can re-phrase the question if nobody understands what we mean to
ask.
Actually, we are not asking for any exact code or any spoon-feeding.
We are asking whether anybody has developed a solution similar to
CursorAdaptor in VFP

Being a completely non-Microsoft person, I'm afraid I can't answer your question.

However, that page contains a lot of tedious info, and I doubt someone would take the time to read through it.

Could you please explain exactly what features "CursorAdapter" has, that you are looking for in Django?

Tom Evans

unread,
Jul 8, 2011, 11:57:52 AM7/8/11
to django...@googlegroups.com
On Fri, Jul 8, 2011 at 4:01 PM, Hummingbird <vineet....@gmail.com> wrote:
> @Cal,
> My apologies if my post has hurted you.
> I didn't mean that.
> I understand that all these open source projects are run by people who
> don't get paid for it.
>
> My point was quite different. It was about knowledge sharing.
> We can re-phrase the question if nobody understands what we mean to
> ask.
> Actually, we are not asking for any exact code or any spoon-feeding.
> We are asking whether anybody has developed a solution similar to
> CursorAdaptor in VFP
> Ed Leafe & Paul McNett have done marvelous work in this area (DABO
> desktop framework).
>
> Instead of making this post very long by giving details of what is a
> CursorAdaptor, pl. refer to --
> http://msdn.microsoft.com/en-us/library/d993hde7(v=vs.80).aspx
>
> Regarding your remark of "Don't expect an instant answer"--
> -- OP was dated 30th June.
> Today is 8th July (an instant???)
>
> Again, pl. excuse me if I have said anything wrong.
> @qMax:  Have you got any way around your question?
>
> ---Vineet
>

Hi Vineet

The problem both you and the OP have is that you asked extremely vague
questions. I've re-read the OPs post a number of times, and all I can
see is some extremely vague discussion on how the ORM represents
tables as model instances. I still don't see a question there, or at
least one I can answer.

Your question is only vaguely related to the OPs (in that it deals
with the ORM). On mailing lists, some people find replying to another
thread with a different question of your own almost as rude as TYPING
IN ALL CAPS. It is best to start a new thread rather than hijacking
someone elses. Secondly, continually bumping a thread each day is also
very annoying. Both of these things will dissuade people from replying
to you, so bear that in mind.

Netiquette apart, your question is vague. You describe a system where
by you can update various tables, updating the ones you want. This is
a basic feature of ORMs - have you read the tutorial or any of the
documentation on django's ORM?

I think the basic point is that you are far too vague about what you
want. You can't just point at us at some MS relational layer
documentation from 2005 and expect us to wade through it, work out
what you are currently doing, work out if that is applicable to
Django's ORM and formulate a plan for you. You are going to need to do
some of the work yourself.

There are more ORMs out there than you can imagine. You need to work
out what you want from a framework, and evaluate the frameworks out
there to find the suitable one for your project. We can help by
telling you about the Django one, but you need to help by telling us
what you want to do with it (consider creating, reading, updating and
deleting items as something that all the frameworks will do).

I think you will find people here will be willing and responsive to
help you, once you figure out what it is that you want from Django,
and start asking precise questions about what Django can support.

Cheers

Tom

Hummingbird

unread,
Jul 8, 2011, 11:53:51 PM7/8/11
to Django users
Although I have gone through the docs of Django ORM, let me re-read
it.
Then I will come back to this thread with specific question.

Thanks for your reply.

On Jul 8, 8:57 pm, Tom Evans <tevans...@googlemail.com> wrote:

Hummingbird

unread,
Jul 14, 2011, 9:00:38 AM7/14/11
to Django users
Hi again !
I went through the docs of django again, but still could not find what
I was looking for.

Definition of my problem (simplified version to keep this post short):

Table names (field names) are are under--

customer (custid, custname, groupid),
custdetl (custid, address, tel, mobile, city)
group (groupid, groupname)

There is a single form for handling tables "customer" and "custdetl".
Consider that a user wants to edit customer details in this form.

He changes groupid,
deletes phone number,
changes address,
adds city (earlier, it was left blank by user).

In effect, "customer" table should receive an update statement,
"custdetl" table should receive delete, update & insert statements.

Beforehand, we do not have any means to know what all interactions the
user will make.

My question is:--
Is there any generic way to do this in django?
OR
Is there any third party class (which can be imported in django)
available for catering to such a need?

( I googled to find 2 such classes.
1) "PyBackend" http://pybackend.sourceforge.net/,
2) "Modeling" by Sébastien Bigaret http://modeling.sourceforge.net/main.html
)

But these projects are not active and therefore are not supported.
Also some issues are there in installing them.

Can anybody pl. help?
Thanks.
> > Tom- Hide quoted text -

Szabo, Patrick (LNG-VIE)

unread,
Jul 14, 2011, 9:08:05 AM7/14/11
to django...@googlegroups.com
Hi,

Are those tables somehow related to each other per FK ?!
In that case i think you might be able to use a model form for that purpose.

I'm not really good with django myself so i might be talking bs.


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
XSLT Developer
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patric...@lexisnexis.at
Tel.: 00431 534521573
Fax: +43 (1) 534 52 - 146


-----Ursprüngliche Nachricht-----

--

Michal Petrucha

unread,
Jul 14, 2011, 9:35:00 AM7/14/11
to django...@googlegroups.com
On Thu, Jul 14, 2011 at 06:00:38AM -0700, Hummingbird wrote:
> Table names (field names) are are under--
>
> customer (custid, custname, groupid),
> custdetl (custid, address, tel, mobile, city)
> group (groupid, groupname)
>
> There is a single form for handling tables "customer" and "custdetl".
> Consider that a user wants to edit customer details in this form.
>
> He changes groupid,
> deletes phone number,
> changes address,
> adds city (earlier, it was left blank by user).
>
> In effect, "customer" table should receive an update statement,
> "custdetl" table should receive delete, update & insert statements.

This is the part I have trouble keeping up. Why should it need one
DELETE, one UPDATE and one INSERT? All of that can be done with one
single UPDATE statement in terms of
UPDATE custdetl SET tel = NULL, address = <new address>, CITY = <new city>
WHERE custid = <some ID>;
Why on earth would you delete a row and then insert a row again? By
issuing a DELETE you don't clear the value of a single column, you
remove entire rows from the table. Same with INSERT.

So either you just use one single UPDATE (which is perfectly fine with
Django and if you use a ModelForm it is as easy as calling
my_form.save()) or we're not talking about three tables with columns
as you described but something much more complicated.

Michal

signature.asc

Hummingbird

unread,
Jul 14, 2011, 10:20:12 AM7/14/11
to Django users
Maybe, I didn't explain the condition properely.

As you say, in this case,
"UPDATE custdetl SET tel = NULL, address = <new address>, CITY = <new
city>
WHERE custid = <some ID>"
is fine in this simplified version.

Suppose when a user removes address, tel, city from table 'custdetl'.
When fields are not nullable (not null=true),
Then update won't do the job.
We NEED to delete the row.

Similarly regarding inserts.
If there is no row in 'custdetl' previously, then user interacts the
form & adds the details, then we NEED insert statement.

In actual project, I have individual forms handling as many as >10
linked tables.
I need to issue insert/update/delete statements to different tables.
Any idea how to go about it?

Thanks.

(p.s. : If you want, I will post one elaborate example.)
>  signature.asc
> < 1KViewDownload- Hide quoted text -

Michal Petrucha

unread,
Jul 14, 2011, 11:12:39 AM7/14/11
to django...@googlegroups.com
On Thu, Jul 14, 2011 at 07:20:12AM -0700, Hummingbird wrote:
> Maybe, I didn't explain the condition properely.
>
> As you say, in this case,
> "UPDATE custdetl SET tel = NULL, address = <new address>, CITY = <new
> city>
> WHERE custid = <some ID>"
> is fine in this simplified version.
>
> Suppose when a user removes address, tel, city from table 'custdetl'.
> When fields are not nullable (not null=true),
> Then update won't do the job.
> We NEED to delete the row.

Maybe it is just me, but still, if the fields are not nullable, then
the user cannot clear his phone number while keeping the rest of his
info there -- either you delete his entire row or you keep something
in each column. Either way, you won't be able to accomplish what you
wrote in the previous e-mail.

> Similarly regarding inserts.
> If there is no row in 'custdetl' previously, then user interacts the
> form & adds the details, then we NEED insert statement.

This all depends on the primary key of the table -- if there is no row
with the specified primary key, Django INSERTs one, otherwise it does
an UPDATE.

In your case I can imagine having custid as the primary key. That way,
if you fill out a form for a customer whose details are not in the
table, they get inserted; otherwise they are updated.

> In actual project, I have individual forms handling as many as >10
> linked tables.
> I need to issue insert/update/delete statements to different tables.
> Any idea how to go about it?

This should be perfectly achievable using formsets. The Django admin
implements this via a mechanism called "InlineAdmin" which is in fact
just a bit of sugar around regular formsets.

> (p.s. : If you want, I will post one elaborate example.)

Dunno, that might help; from the one you supplied thus far it is
really not clear what you want to accomplish.


Michal

signature.asc
Message has been deleted
Message has been deleted

Tom Evans

unread,
Jul 14, 2011, 12:26:21 PM7/14/11
to django...@googlegroups.com
On Thu, Jul 14, 2011 at 5:11 PM, Hummingbird <vineet....@gmail.com> wrote:
> What I want to accomplish from these tables is as given below.
>
> All the customer data can be maintained in a single table.
> i.e. customer(custid, custname, groupid, address, tel, mobile, city)
>
> In the course of normalising the database, we arrived at defining 2
> tables.
> "customer" table maintaining basic data like name, group, etc.
> "custdetl" table containing other details of customer.
>
> A row in custdetl will be created only if there is any data like
> address, tel, etc. for a customer.
> (of course, I need not dive into normalisation concept here).
>
> As I said earlier, there are much complex examples of "single form :
> many tables" in my actual project
>
> Thanks.
>

All of this easily doable in django.

Typically when handling forms for editing models, you would create a
ModelForm, which represents one specific model/table. However, you can
include as many ModelForms as you want within one <form>.

A good (and complex) example of this is django's admin system which
allows you to include other models 'inline' when editing a related
model. I think an earlier respondent alluded to this.

Did you have specific questions? Django is quite easy to use and quick
to prototype in, perhaps you should try implementing a prototype in
django to see if it does suit your needs, asking questions on here
when you get stuck.

Cheers

Tom

Hummingbird

unread,
Jul 14, 2011, 12:34:50 PM7/14/11
to Django users
I am presently using web2py.
Before getting the feet wet in django, I am trying to assess whether
the functionality I mentioned in earlier reply is already built-in in
django, by consulting the list-users.
If this is doable, I would happily dive into django.
That's why I did not go into actual coding with django, but asking
questions like "can I do thing-1, thing-2, etc."

Thanks.

On Jul 14, 9:26 pm, Tom Evans <tevans...@googlemail.com> wrote:
> Tom- Hide quoted text -

Tom Evans

unread,
Jul 14, 2011, 1:01:46 PM7/14/11
to django...@googlegroups.com
On Thu, Jul 14, 2011 at 5:34 PM, Hummingbird <vineet....@gmail.com> wrote:
> I am presently using web2py.
> Before getting the feet wet in django, I am trying to assess whether
> the functionality I mentioned in earlier reply is already built-in in
> django, by consulting the list-users.
> If this is doable, I would happily dive into django.
> That's why I did not go into actual coding with django, but asking
> questions like "can I do thing-1, thing-2, etc."
>
> Thanks.
>

Let me answer all of them up front:

thing-1: yes
thing-2: yes
thing-3: yes
thing-N: yes

As I often tell my boss, this is software development, we can do anything*.

Developing a prototype, even spending just an hour defining the models
and playing around in the admin (so no real coding) would tell you
whether to proceed or not. But it's your choice, I guess we'll have
another two weeks of 'interesting' questions.

Tom

* (given enough time and resource)

Hummingbird

unread,
Jul 14, 2011, 1:06:40 PM7/14/11
to Django users
All right Tom.
Let me look into admin.
Then perhaps I would require the help from list.

Cheers.

On Jul 14, 10:01 pm, Tom Evans <tevans...@googlemail.com> wrote:

Javier Guerra Giraldez

unread,
Jul 14, 2011, 1:13:33 PM7/14/11
to django...@googlegroups.com
On Thu, Jul 14, 2011 at 12:06 PM, Hummingbird <vineet....@gmail.com> wrote:
> All right Tom.
> Let me look into admin.
> Then perhaps I would require the help from list.

I (like everybody else here) don't want to sound rude; but i don't
think you'll get anywhere with this approach.

Django is a big framework, just reading random doc sections won't tell
you about the 'big picture'. without a good idea of what is there,
how parts fit and how to approach your problem(s), you won't be able
to ask the right questions.

far better is to do what was suggested to you long ago: do the tutorial.

before you finish it, you'll see why your questions are unanswerable,
and if you like Django or not.

--
Javier

Andre Terra

unread,
Jul 14, 2011, 1:39:22 PM7/14/11
to django...@googlegroups.com
far better is to do what was suggested to you long ago: do the tutorial.

before you finish it, you'll see why your questions are unanswerable,
and if you like Django or not.


This cannot be stressed enough.

And do read the wiki guide on posting to the mailing list, as most of your posts were too vague and simply devoid of a real *Django* question.

I don't mean to sound crass, but spamming the list like that is exactly the reason why we can't answer every question immediately.



Regards,
André Terra / airstrike
Reply all
Reply to author
Forward
0 new messages