0

I have a "Job" object when I do

   jobs=Job.objects.exclude(end_time__lte =datetime.now(), isActive=True)

or

   jobs.filter( isActive=True)

isAvtive query doesn't wotk at all. What can be the problem? I use MySQL, in job table True register as 1 , Fakse Register as 0 , nad the Job model :

class Job(models.Model):
title=models.CharField(max_length=40)
genre=models.ManyToManyField(JobGenre)  
location=models.TextField()
start_time=models.DateTimeField()             
end_time=models.DateTimeField()
description=models.TextField()
reward=models.TextField(null=True)
isActive=models.BooleanField(default=True)


def __unicode__(self):
    return self.title

class meta:
    ordering=['-end_time','creator']
3
  • Why do you think it's not working? It should work, look for the problem somewhere else. Also look at this question: stackoverflow.com/questions/2221247/… Commented Apr 17, 2013 at 14:36
  • it show resluset with false and true values in "isActive" Commented Apr 17, 2013 at 14:42
  • 1
    What does your Job model look like? Commented Apr 17, 2013 at 14:49

1 Answer 1

2

It's not clear what you're trying to achieve. If you want all records where isActive is TRUE, then...

jobs = Job.objects.filter(isActive=True)

...should work. If you want to exclude all records where isActive is TRUE, then you want...

jobs = Job.objects.filter(isActive=False)

One of these two should return some results, unless your DB table has no data in it.

Sign up to request clarification or add additional context in comments.

5 Comments

This time nothing is return :(
@hln Then perhaps there are no records in the database where isActive is TRUE. It might help to include the code for your Django Job model, and a small sample of the data for that database table in your question.
there are false and true job objects,
@hln Are you certain the Django is connecting to the correct database? If you're making a unit test, Django will create a temporary database with no content, so you'll have to provide a fixture.
Sorry it works, i dont know why suddently all data in datbase was dispeared. :( and it cant use jobs=Job.objects.exclude(end_time__lte =datetime.now(), isActive=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.