Hi

need a help with this queryset problem
i got into my models.


models.py
---------

class Classi(models.Model):
    classi = models.CharField('Class Name', max_length='20', unique=True)
    internet = models.BooleanField(default=None)

using Calssi can do:
create: A, B. C

class Prof(models.Model):
    prof = models.ForeignKey(User)
    classi = models.ManyToManyField(Classi)

i can create a simple User: teacher, and can belong to A, C  Classi

class MAC(models.Model):
    classi = models.ForeignKey(Classi)
    name = models.CharField('dev_name', max_length=64, default='unnamed',
null=True, blank=True)
    mac = MACAddressField('MAC', blank=False, unique=True)
    internet = models.BooleanField(default=None)

i create simple macs objects where those belongs to Classi

after that i got

admin.py
--------

class ClassAdmin(admin.ModelAdmin):
 def get_queryset(self, request):
        qs = super(ClassAdmin, self).get_queryset(request)
        if request.user.is_staff and request.user.is_superuser:
            return qs
        return qs.filter(prof__prof=request.user)

with this I can see only Classi A and B if I logged as User with A and B
classrooms set it and that's ok

but:
--------------------------------------------
i'm testing 4 macs:  Class A: 1mac ,   Class B: 2mac,   Class C: 1mac

when i define:

class MacAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        qs = super(MACAdmin, self).get_queryset(request)
        if request.user.is_staff and request.user.is_superuser:
            return qs
        return qs.filter(classi_id__mac=request.user)

for make a test I create an user belogs to Class A and B so would be see 3
macs on list_display
but only got 1

on debug mode, qs variable i can see the 4 macs,   i need to know filter it
to get only that A and B because is filtered by user wich only belogs to A
and B class

thanxs

-- 
Antonio Peña
Secure email with PGP 0x8B021001 available at https://pgp.mit.edu
<https://pgp.mit.edu/pks/lookup?search=0x8B021001&op=index&fingerprint=on&exact=on>
Fingerprint: 74E6 2974 B090 366D CE71  7BB2 6476 FA09 8B02 1001

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALBaCdspx8LwbiY1i_cbbxRE8TNSbrVHf4YoULBAZmr0koziQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to