Friday, September 28, 2012

Re: How to separate data having the same model but belonging to different users?

Use unit tests so you DO NOT FORGET to user the userid filter.

You're going to walk a thousand miles to get something somewhat working and that it won't solve all your problems. At least, resolving the "forgetting the filter" issue is easy to solve.

When you database starts to creep with tables you are going to have a nightmare. Oh, imagine when you need to cross compare these tables...if they were only one table...it would be easy. Imagine reports.´You will need to query n tables instead of one. Thats n - 1 chances to construct the wrong sql.

But that's up to you.

On Fri, Sep 28, 2012 at 3:49 PM, Joel Goldstick <joel.goldstick@gmail.com> wrote:
On Sun, Sep 23, 2012 at 9:32 PM, Rohit Banga <iamrohitbanga@gmail.com> wrote:
> How about maintaining one database per department and then using "using"
> parameter to select the appropriate database?
> There are not too many departments. I know it may not scale or seem elegant
> but keeping data in separate tables or databases is a requirement.
> Using the following command I feel I can sync all models to a new database.
>
> ./manage.py syncdb --database=department1
>
> Do you foresee any problem with this solution?
> I am planning to have a default database with all users and groups and then
> based on the group select the appropriate database.
> I do not want to sync django-admin tables to all databases. Is there a way
> to restrict models to a specific database?
> Let say I have databases 0 ... n.
> Departments 1 to n have the same set of tables with different data and
> database i corresponds to department i.
> database 0 is used to store only admin database tables. Is there a
> reasonable way to restrict this within the same app or are there problems
> that I cannot foresee?
>
> Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
> On Sun, Sep 23, 2012 at 12:56 PM, Dennis Lee Bieber <wlfraed@ix.netcom.com>
> wrote:
>>
>> On Sat, 22 Sep 2012 22:04:41 -0700 (PDT), Bill Beal
>> <b.beal@eximflow.com> declaimed the following in
>> gmane.comp.python.django.user:
>>
>> >
>> > I should think that if you have a foreign key to the department in all
>> > tables that must be segregated by department, you could create a
>> > decorator
>> > that would apply a filter with the department key.  But I don't know how
>> > to
>> > do it.
>> >
>>         Which basically puts it back to what the OP insists they are not
>> permitted to do -- have a single set of tables with a selection based on
>> the logged in user's department.
>> --
>>         Wulfraed                 Dennis Lee Bieber         AF6VN
>>         wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


I just came across the Section on Managers in the Django book (p 197
in the second edition) here online:
http://www.djangobook.com/en/2.0/chapter10.html

Search for the section on Managers.  This would be an excellent way to
solve your problem.  Using one model you can use different managers
which filter on Department Name
--
Joel Goldstick

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




--
George R. C. Silva

Desenvolvimento em GIS
http://geoprocessamento.net
http://blog.geoprocessamento.net

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

No comments:

Post a Comment