Hi Chris,

You could copy the whole model, ala DynamicModels on the wiki [
http://code.djangoproject.com/wiki/DynamicModels], I've sketched out a more
complete example here: http://www.djangosnippets.org/snippets/442/. This
example (I say example as it's a bit rough around the edges - especially the
field copying code!) was needed when working with the old multi-db branch to
specify a different database, so there are some things that won't work with
trunk (the references to "connections" for example). The advantage of
copying the whole model is that you can then do anything you want with it
and the django API doesn't change.

Cheers,
Ben

2008/5/29 ChrisStoyles <[EMAIL PROTECTED]>:

>
> Hi Everyone,
>
> I've been doing some prototyping with django to see how good of a fit
> it will be for an upcoming project, and would like to run an idea past
> you guys. I'll try and explain my situation first, and then ask the
> question afterward.
>
> At a very high level, I have an application, which holds many
> organisations, and these organisations each contain many products. I
> may need to at times, partition the product data, so that some
> organisation products are stored in table 'a' and others are stored in
> table 'b'. However the Product as a model class is the same between
> both of these, and I won't know the names of these tables until
> runtime (they may be based on organisation names, which would be
> created by users).
>
> So as you might already have guessed, I would like to be able to use
> my "Product" model class across many tables. I would do this by
> changing the value of db_table. This however only works for saving an
> instance of Product (I can change the db_table value for that
> instance, prior to saving, and it will be committed to said table). I
> cannot however change the db_table property for a single thread, so as
> to fetch a Product from any arbitrary table name.
>
> I believe what would be needed is the ability to supply a context at
> runtime, from which db_table could be determined, i.e.
> Product.objects.all(ctx) where ctx.db_table is the name of the product
> table I wish to use
>
> That is a very quick and dirty example, however I hope I have still
> made sense and might be able to get some feedback from the developer
> community.
>
> Thanks!
> Chris
> >
>


-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+447792598685

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

Reply via email to