Wednesday, February 27, 2013

default filtering model admin (crud) using user obj attribute

Dear All..

Currently I have custom authentication backend,
This backend return user-object with additional attributes

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.
>>> 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,
>>> myuser.company_id_id

My concern is 'myuser.company_id', this attribute is a ForeignKey to
'Company' model.

I also have 'Car' model like :
class Car(models.Model) :
company_id = models.ForeignKey()
badge = models.CharField('Badge', max_length=10)

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
3. Delete : Only posible for Car.company_id=myuser.company_id

Kindly please give me any of your enlighten.


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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment