I added a calculated field in my model and it is working pretty fine.
I want to get only the data with a certain value of this calculated field.
My model:
class Bdc(models.Model):
ORDRE = (('Nominatif', 'Nominatif'), ('Au porteur', 'Au porteur'))
EPARGNE = (('3', '3'), ('6', '6'), ('12', '12'), ('24', '24'), ('36', '36'))
conseiller=models.ForeignKey(Conseiller, null=True, on_delete=models.CASCADE)
radical = models.CharField(max_length=200, null=True)
ordre = models.CharField(max_length=200, choices=ORDRE, null=True)
montant = models.FloatField(null=True)
taux = models.FloatField(null=True)
date_emission = models.DateField(null=True)
dureeE = models.CharField(max_length=200, null=True, choices=EPARGNE)
date_paiment = models.DateField(null=True)
def __str__(self):
return self.radical
@property
def Days_till(self):
today = date.today()
days_till = self.date_paiment - today
days_till_stripped = str(days_till).split(" ", 1)[0]
if days_till_stripped < '0':
return 0
a = int(days_till_stripped)
return a
@property
def bpr(self):
BPR = self.conseiller.bpr
return BPR
@property
def state(self):
if self.Days_till == 0:
return 'payƩ'
return 'non payƩ'
My view
@login_required(login_url='connexion')
@allowed_users(allowed_roles=['Admins'])
def bdc(request):
bdcs = Bdc.objects.all().order_by('state')
conseillers = Conseiller.objects.all()
myFilter = BdcFilter(request.GET, queryset=bdcs)
bdcs = myFilter.qs
context = {'conseillers': conseillers, 'bdcs': bdcs,'myFilter':myFilter}
return render(request,"comptes/bdc.html", context)
The error m getting from django:
Cannot resolve keyword āstateā into field. Choices are: conseiller, conseiller_id, date_emission, date_paiment, dureeE, id, montant, ordre, radical, taux
In fact I used order but the same error thta i am getting while using āFilterā.
I want to have the data that have Days_till = 0.
Thank you!