I am working with django and having a hard time grasping how to do complex queries
Here is my model
class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.DateTimeField(auto_now=True) title = models.CharField(max_length=50) body = models.TextField() class Meta: ordering = ('-ts',) get_latest_by = 'ts'
I need to pull the username given the tank object.
The user object is the one built into django.. thanks!
EDIT:
I have tried this
print User.objects.filter(tankjournal__tank__exact=id)
It seems to not pull out just the id.. and pull out everything in tankjournal and match it to the tank object
If you already have your tank object you should be able to do:
To reduce the database queries you might want to consider the use of select_related(), e.g.
if you have a specific tank id then: