Django form and User data
- by Dean
I have a model that looks like this:
class Client(models.Model):
name = models.CharField(max_length=100, primary_key=True)
user = models.ForeignKey(User)
class Contract(models.Model):
title = models.CharField(max_length=100, primary_key=True)
start_date = models.DateField()
end_date = models.DateField()
description = models.TextField()
client = models.ForeignKey(Client)
user = models.ForeignKey(User)
How can i configure a django form so that only clients associated with that user show in the field in the form?
My initial thought was this in my forms.py:
client = forms.ModelChoiceField(queryset=Client.objects.filter(user__username = User.username))
But it didn't work. So how else would I go about it?