Hi!

A few days ago I've post a question about changing the unicode on a form
This was the answer:

one way is to override __init__. Here is a sample:
class Accountaddform(ModelForm):
    def __init__(self,head,*args,**kwargs):
        super (Accountaddform,self).__init__(*args,**kwargs)
        self.head = head
        self.fields['head'].queryset=Account.objects.filter(pk=self.head)
    class Meta:
        model = Account

(thanks Kenneth Gonsalves, it works as I wanted!)

Now I want to change the queryset.
I'm using the contib.auth.
I have a model wich I named Teacher and another wich I named Pupil.

After a user sign in the system, the admin classifies him as a theacher or a 
pupil. 
In self.fields['head'].queryset=Account.objects.filter(pk=self.head) I want to 
change the queryset to only appears the pupils, it should return all the 
records wich have an id in both models User and Pupil.

Now I have this

class Pupil(models.Model):
    user = models.ForeignKey(User)
    nr = models.IntegerField(blank=True,)
    gender = models.CharField(max_length=1, blank=True, 
choices=gender_choices)
...

class Teacher(models.Model):
    user = models.ForeignKey(User)
    schools = models.ManyToManyField(School, null=True, blank=True)
...


class Couple(models.Model):
    man = models.ForeignKey(Aluno, related_name='man',)
    woman = models.ForeignKey(Aluno, related_name='woman',)
...
   

class CoupleForm(ModelForm):
    class Meta:
        model = Couple
        
    def __init__(self, *args, **kwargs):
        super(CoupleForm, self).__init__(*args, **kwargs)
        self.fields['man'].queryset=Pupil.objects.filter(gender='M')
        self.fields['woman'].queryset=Pupil.objects.filter(gender='F')

It returns only the man and woman for each combo box. Now, also, I only want 
the User wich aren't Teacher. How can I do this? I've tried with Manager.raw() 
but it doesn't work or I don't know how to use it

Thanks

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

Reply via email to