@login_required
def searchProduct(request):
"""
to search a particular product with name
"""
search_terms =''
if request.GET['search_term']:
search_terms = request.GET.get('search_term')
if search_terms:
products = models.Product.objects.filter(product_name__icontains=search_terms)
for product in products:
kitchenstyle = KicthenStyleMapping.objects.filter(product= product)
print kitchenstyle
return render_to_response('admin/product/searchListProduct.html',{'search_terms': search_terms,'products' : products }, context_instance=RequestContext(request))
return HttpResponseRedirect('/')
class KicthenStyleMapping(models.Model):
style_mapping_id = models.AutoField(primary_key=True)
style = models.ForeignKey(KitchenStyle)
product = models.ForeignKey(Product)
class Meta:
db_table = 'kicthen_style_mapping'
class KitchenStyle(models.Model):
id = models.AutoField(primary_key=True)
style_name = models.CharField(max_length=248L, blank=True)
description = models.TextField(blank=True)
estimated_time = models.CharField(max_length=100L, blank=True)
status = models.CharField(max_length=10L)
class Meta:
db_table = 'kitchen_style'
class Product(models.Model):
id = models.AutoField(primary_key=True)
cabinet = models.CharField(max_length=100L, blank=True)
material = models.ForeignKey(Materials)
category = models.ForeignKey(Category, null=True, blank=True)
sub_category = models.ForeignKey(SubCategory, null=True, blank=True)
product_name = models.CharField(max_length=135, blank=True)
product_code = models.CharField(max_length=135, blank=True)
short_description = models.TextField(blank=True)
descriptions = models.TextField(blank=True)
product_price = models.FloatField(null=True, blank=True)
min_height = models.FloatField(null=True, blank=True)
max_height = models.FloatField(null=True, blank=True)
height_scale = models.FloatField(null=True, blank=True)
min_width = models.FloatField(null=True, blank=True)
max_width = models.FloatField(null=True, blank=True)
width_scale = models.FloatField(null=True, blank=True)
min_depth = models.FloatField(null=True, blank=True)
max_depth = models.FloatField(null=True, blank=True)
depth_scale = models.FloatField(null=True, blank=True)
is_hinges = models.CharField(max_length=12)
image = models.CharField(max_length=135, blank=True)
is_door = models.CharField(max_length=12, blank=True)
discount = models.FloatField(null=True, blank=True)
is_drawer = models.CharField(max_length=12)
video_url = models.CharField(max_length=200L, blank=True)
is_custom = models.CharField(max_length=4L)
class Meta:
db_table = u'product'
我是 django 的新手。我没有使用 django 搜索或任何其他内置搜索模块。在搜索产品功能中,我无法过滤以产品字段为外键的 kitchenstylemapping 模型。任何帮助表示赞赏