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']
hln
  • 1,071
  • 4
  • 21
  • 37
  • Why do you think it's not working? It should work, look for the problem somewhere else. Also look at this question: http://stackoverflow.com/questions/2221247/why-doesnt-this-loop-display-an-updated-object-count-every-five-seconds/2221400 – alex vasi Apr 17 '13 at 14:36
  • it show resluset with false and true values in "isActive" – hln Apr 17 '13 at 14:42
  • 1
    What does your `Job` model look like? – Ngenator Apr 17 '13 at 14:49

1 Answers1

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.

Aya
  • 39,884
  • 6
  • 55
  • 55
  • This time nothing is return :( – hln Apr 17 '13 at 14:42
  • @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. – Aya Apr 17 '13 at 14:45
  • there are false and true job objects, – hln Apr 17 '13 at 15:00
  • @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. – Aya Apr 17 '13 at 15:07
  • 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) – hln Apr 17 '13 at 15:35