Django form and User data
Posted
by
Dean
on Stack Overflow
See other posts from Stack Overflow
or by Dean
Published on 2011-02-13T23:18:41Z
Indexed on
2011/02/13
23:25 UTC
Read the original article
Hit count: 225
django
|django-forms
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?
© Stack Overflow or respective owner