On Thu, Feb 28, 2013 at 7:37 AM, Bino Oetomo <[email protected]> wrote:
> Dear All..
>
> Currently I have custom authentication backend,
> This backend return user-object with additional attributes
>
> --------START--------
> Python 2.7.3 (default, Aug  1 2012, 05:16:07)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>>>> from l2auth.models import Company
>>>> from csm.models import L2User, L2Group
>>>> from l2auth.backends import L2Backend
>>>> myauth = L2Backend()
>>>> myauth.authenticate('user02@binonet','1111')
> L2Backend => user02@binonet 1111
> ['user02', 'binonet']
> company_id => 1
> user==> user02
> <L2User: user02>
>>>> myuser=myauth.authenticate('user02@binonet','1111')
> L2Backend => user02@binonet 1111
> ['user02', 'binonet']
> company_id => 1
> user==> user02
>>>> myuser.company_id
> <Company: binonet>
>>>>
>>>> myuserdict=myuser.__dict__
>>>> myuserdict
> {'username': u'user02', 'first_name': u'user 02', 'last_name': u'of
> binonet', '_state': <django.db.models.base.ModelState object at
> 0xa7890ac>, '_company_id_cache': <Company: binonet>, 'company_id_id':
> 1, 'email': u'', 'is_active': True, 'is_superuser': False, 'is_staff':
> False, 'last_login': datetime.datetime(2013, 2, 28, 7, 1, 41, 521980,
> tzinfo=<UTC>), 'password': u'pbkdf2_sha256$10000$0NrkpAjo4osS
> $nFdAVaH9mlAbE9vzAvlj+aQeTP7gQsUpFZLZTYOVggs=', 'id': 2,
> 'date_joined': datetime.datetime(2013, 2, 28, 6, 58, 41,
> tzinfo=<UTC>)}
>>>> myuser.company_id_id
> 1
> --------STOP---------
>
> My concern is 'myuser.company_id', this attribute is a ForeignKey to
> 'Company' model.
>
> I also have 'Car' model like :
> ----------START------------
> class Car(models.Model) :
>     company_id = models.ForeignKey()
>     badge = models.CharField('Badge', max_length=10)
> ----------STOP-------------
>
> By Default, every user login .. he/she have full access (CrUD) to all
> cars, including other company's car.
>
> My question is how to make :
> 1. Car list : Only show cars with company_id=myuser.company_id
> 2. Create/Update : 'Company choice list' locked to the one with
> value=myuser.company_id
> 3. Delete : Only posible for Car.company_id=myuser.company_id
>
> Kindly please give me any of your enlighten.
>
> Sincerely
> -bino-
>

It seems like you are asking how to do multi-tenancy in the stock django admin?

Multi tenancy is tricky in django. Is there any reason you are not
using one of the already existing multi-tenancy efforts?

Cheers

Tom

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to