objects.filter

25 views
Skip to first unread message

pujiarahman

unread,
Nov 30, 2018, 1:28:22 AM11/30/18
to Django users
helo, 
iam new for python.  

my : models.py

lass logbook_noc(models.Model):
idLogbookN = models.IntegerField(primary_key=True)
kodetiket = models.CharField(max_length=30)
CustName = models.CharField(max_length=30)
TanggalLo = models.DateTimeField()
DeskripsiLo = models.TextField()
StatusProgress = models.CharField(max_length=30)
PenangananLo = models.TextField()
TglUpdate = models.DateTimeField()


class Meta:
managed = False
db_table = 'logbook_noc'
def __str__(self):
return self.Id

  
 my: views.py

def home(request):
logbooks = logbook_noc.objects.filter(StatusProgress = '1 Pending' )
paginator = Paginator(logbooks, 8)
page = request.GET.get('page')
pb = paginator.get_page(page)
return render(request, 'blog/home.html', {'pb':pb})


how to add  one word again to filter like '2 On Progress'
i tray to logbooks = logbook_noc.objects.filter(StatusProgress = '1 Pending' or '2 On Progress' )
the output for status is only 1 Pending the 2 On Progress not display..

Thanks

Todor Velichkov

unread,
Dec 1, 2018, 12:17:50 AM12/1/18
to Django users
It would be

logbook_noc.objects.filter(StatusProgress__in = ['1 Pending', '2 On Progress'])

You can read more about this at Making queries and please take a look at Coding styles and PEP8, because reading this code is a pain.

Aqilah Maulidya Sidik

unread,
Dec 1, 2018, 12:52:14 AM12/1/18
to django...@googlegroups.com
Hi todor, 

Thanks very much you save my day... 

Regards

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3f69d7a1-e522-450c-99f6-62506652b3d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages