Friday, May 27, 2011

Form and ForeignKey Limiting

Hi,
I am having a bit of a problem with a form.

example (mind the psudo code)
(Model user: included in Django)

Model manager:
    user = ForeignKey(user)

Model task:
    user = ForeignKey(user)
manager = ForeignKey(manager)

What I want to do somehow. Is with a form, being able to create a new
task, and select a manager. (Must be set)
The tricky part is that I ONLY want managers with "user == current
user" to be options.
ModelChoiceField is apparently out of the question; because there is
no way, that i can find, that let me access request.user to narrow the
queryset down.

Am I looking at this problem the wrong way?
I was thinking of adding a field with a non-existing widget (no HTML
rendered) and let the view render the field in HTML; but I can't find
a None-widget.
My total backup everything else fails is to use a ChoiceField with a
Select widget, and write some AJAX code to fill in the data, but that
would require javascript support.

I'll give more details if needed.

Thanks.
----------Desktop Browser---------
Christoffer Viken / CVi
i=0
str="kI4dJMtXAv0m3cUiPKx8H"
while i<=20:
    if i%3 and not i%4:
        print str[i],
    i=i+1

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate