django models objects filter

Posted by ha22109 on Stack Overflow See other posts from Stack Overflow or by ha22109
Published on 2010-04-23T12:16:35Z Indexed on 2010/04/23 13:23 UTC
Read the original article Hit count: 418

Hello All,

I have a model 'Test' ,in which i have 2 foreignkey

models.py

class Test(models.Model):
    id =models.Autofield(primary_key=True)
    name=models.ForeignKey(model2)
    login=models.ForeignKey(model1)
    status=models.CharField(max_length=200)



class model1(models.Model):
   id=models.CharField(primary_key=True)
   .
   .

   is_active=models.IntergerField()


 class model2(model.Model):
    id=models.ForeignKey(model1)
     .

     .
     status=model.CharField(max_length=200)

When i add object in model 'Test' , if i select certain login then only the objects related to that objects(model2) should be shown in field 'name'.How can i achieve this.THis will be runtime as if i change the login field value the objects in name should also change.

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models