【发布时间】:2016-06-10 07:11:18
【问题描述】:
我是 Django 的新手。我有一个 mySQL 查询:
SELECT username, foto FROM a INNER JOIN b ON (a.user_id = b.id) INNER JOIN c ON (a.foto_id = c.id)
在Django中怎么写?
型号:
class b(models.Model):
username = models.CharField(max_length=30)
email = models.CharField(max_length=30)
password = models.CharField(max_length=30)
class c(models.Model):
user_id = models.IntegerField()
foto = models.FileField(upload_to='documents')
created_at = models.DateTimeField(auto_now_add=True)
class a(models.Model):
user_id = models.IntegerField()
foto = models.ForeignKey('c', blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
【问题讨论】:
-
我认为如果你展示你的模型会更容易。
标签: python django django-queryset django-orm