This is my models.py
class The_loai(models.Model):
ten = models.CharField(max_length= 150, unique= True)
def __str__(self):
return self.ten
class Thanh_pho(models.Model):
ten_tp = models.CharField(max_length= 150, unique= True)
def __str__(self):
return self.ten_tp
class Quan(models.Model):
ten_tp = models.ForeignKey(Thanh_pho, on_delete=models.PROTECT)
ten_quan = models.CharField(max_length= 150, unique= True)
def __str__(self):
return self.ten_quan
class Chi_tiet(models.Model):
ten = models.CharField(max_length= 150, unique= True)
dia_chi = models.CharField(max_length=300, unique= True)
the_loai = models.ForeignKey(The_loai, on_delete=models.PROTECT)
ten_tp = models.ForeignKey(Thanh_pho, on_delete=models.PROTECT)
ten_quan = models.ForeignKey(Quan, on_delete=models.PROTECT)
thong_tin = models.TextField()
hinh_anh = models.ImageField(upload_to=None, height_field=None, width_field=None)
def __str__(self):
return self.tentype here
And this is my views.py
def blog(request):
chi_tiet = Chi_tiet.objects.all().filter(the_loai = "Miếu")
return render(request, 'blog.html', {'chi_tiet': chi_tiet})
This appeared :
Field 'id' expected a number but got 'Miếu'.
I tried to use the_loai‘s id instead of a name, but nothing was appeared
What i expected is just to show all objects have the word i need
Please help me, Thank you !
New contributor
Pierre De Ampère is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.