I have the below choice field in models.
STATUS_REVIEW_RISK_ESTIMATE_CHOICES = (
(0, "High"),
(1, "Medium"),
(2, "Low"),
)
class SiverifyProblemStatement(models.Model):
risk_estimate = models.PositiveIntegerField(null=True, blank=True, choices=STATUS_REVIEW_RISK_ESTIMATE_CHOICES)
When I try to render the values from db(eventually stored as integers(0,1,2). I'm using the following code which helps me to display the name of the choices(High, Medium and low).
Render code:
def render_risk_estimate(self, **kwargs):
try:
stmt = kwargs['row_obj'].revision_problem_statements.latest('id')
except ObjectDoesNotExist:
return None
return (stmt and stmt.get_risk_estimate_display() or None)
But when I try to establish the same for searching the field with choice names, I get an error stating get_risk_estimate_display() is not an attribute. However, when I tried this, I'm able to search the field with integer choices.
Tried code:
class ReviewWorklistDTView(GroupDTListView):
columns = [{'data': 'risk_estimate','_get': 'id', 'title':'Risk Estimation', '_search':'revision_problem_statements__risk_estimate', '_type': 'char'},]
This helps me in searching with the integer choices not with respect to the values in it. I did looked up at the following questions, but nothing seems to be helping my part.
http://stackoverflow.com/questions/22043054/search-field-by-field-choice
http://stackoverflow.com/questions/12626171/django-admin-choice-field
https://github.com/sivaa/django-custom-search-filter/blob/master/app/admin.py