1
我是Django中的新成員。我有一個MySQL查詢:Django兩個內部聯接
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)
我想,如果你表現出你的模型,這將是更容易。 – Gocht