You’re close
name = django_filters.CharFilter(field_name='item',lookup_expr='exact')
the thing is my model is
class Item(models.Model):
CATEGORY = (
('Gudang Kering', 'Gudang Kering'),
('Gudang Basah','Gudang Basah'),
)
name = models.CharField(max_length=200,null= True)
stock = models.IntegerField(default='0', blank=False, null=True)
category = models.CharField(max_length=200,null= True,choices=CATEGORY)
reorderlevel = models.IntegerField(default='0', blank=False, null=True)
maxreorderlevel = models.IntegerField(default='0', blank=False, null=True)
description = models.CharField(max_length=200,null= True, blank= True)
date_created = models.DateTimeField(auto_now_add= True)
tags = models.ManyToManyField(Tag)
def __str__(self):
return self.name
class Issue(models.Model):
STATUS = (
('Pending', 'Pending'),
('Granted','Granted'),
('Denied','Denied'),
)
customer = models.ForeignKey(Customer, null=True, on_delete= models.SET_NULL)
item = models.ForeignKey(Item, null=True, on_delete= models.SET_NULL)
quantity = models.IntegerField(default='0', blank=False, null=True)
date_created = models.DateTimeField(auto_now_add=True, auto_now=False)
status = models.CharField(max_length=200,null= True, choices=STATUS)
def __str__(self):
return str(self.quantity)+' '+str(self.item)+' '+self.status + ' ' +str(self.customer)
it returned the value of item(foreignkey) as an int,so i can’t use charfilter.
i tried booleanfield, it returned the name but unlike version from before where we can type the item name to search it became a choice like field where i chose inputed data from before on search
in the past i just need to do my form like so
class IssueFilter(django_filters.FilterSet):
class meta:
model = Issue
fields = '__all__'
#when called this
fields = '__all__'
will make it so django filter autogenerate the search form to include all fields from model