---models.py---
class Products(models.Model):
category = models.ForeignKey(Category)
name= models.CharField(max_length=120, unique=True)
slug = models.SlugField(unique = True)
price = models.IntegerField(default=100)
class Image(models.Model):
property = models.ForeignKey(Products, related_name='images')
image = models.ImageField(upload_to='static/images/home',blank=True,null=True)
---views.py----
if request.is_ajax():
query = Products.objects.all()
p = Paginator(query, 4)
pagedata = p.page(1)
jsondata = serializers.serialize('json', pagedata.object_list)
data = json.dumps({'id' : jsondata,})
return HttpResponse(data, content_type='application/json')
现在在 ajax 中的数据在 (pk, category, name, slug ,price)
但我也想要在 ajax 中使用反向查找的外键字段,即“图像”。我已经尝试过列表,但我想使用反向查找..