In your form for your payment, you need to create an __init__ function
that sets the queryset for thh account field. This allows you to set
it dynamically for each form. Something like this:
class PaymentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
accountQuerySet = kwargs.pop("accountQuerySet")
super(PaymentForm, self).__init__(*args, **kwargs)
self.fields['account'].queryset = accountQuerySet
Here's a write up by malcolm with more eplanation:
http://groups.google.com/group/django-users/browse_frm/thread/cd60e30e25a093a0/6c3a5b6b2476c4a4?lnk=gst&q=form+fields+queryset#6c3a5b6b2476c4a4
If you search teh group for "form fields queryset" you'll find lots
more.
Margie
On Apr 29, 6:36 am, cfiles <[email protected]> wrote:
> Let me try to explain this a little more. Here are some example models
>
> class Account(models.Model):
> user = models.ForeignKey(User)
> name = models.CharField('Name on Account', max_length=100)
> description = models.CharField(max_length=100)
> date_added = models.DateField(auto_now_add=True, blank=True)
>
> class Payment(models.Model):
> account = models.ForeignKey(Account)
> date_paid = models.DateField(auto_now_add=True, blank=True)
> amount = models.DecimalField(max_digits=10, decimal_places=2)
>
> When I display the form for a Payment I get all of the Account
> objects. I want to limit the list to accounts that the user owns. How
> is this done? I have looked an I am unable to find the documentation
> for it.
>
> On Apr 27, 1:27 pm, cfiles <[email protected]> wrote:
>
> > I have a model with a ForeignKeyto another model. Is it possible to filter
> > the HTML select list for the foreign object from a view?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---