I don't see much reason to keep Payment method separate from the Orders
class then. For each order, you can have a different payment method, so just
make a payment method column in the Orders model. Like this:

payment_method_choices = (
    ('$$', 'Cash'),
    ('cc', 'Credit Card'),
)

class Order(models.Model):

    id = models.ForeignKey(CustomerProfile)
    payment_method = models.CharField(max_length=32, choices =
payment_method_choices)

By including specific choices the drop-down menu will get rendered
automatically by the form (at least on the admin screen...you'll need to do
it yourself in your templates as a drop down menu).

At least, this is what I think I would do.

-Tim


On Sat, Feb 27, 2010 at 5:17 AM, django_is <festival.s...@googlemail.com>wrote:

> Yeah I understand that. But it makes no sense to link the payment
> field in my Orders model to the CustomerProfile.
> In the end I want to save one payment method from the methods that are
> available for one specific user in my record for one order. I'm just
> confused on how to achieve that. From a user perspective I'd like to
> get a dropdown when adding one order in the backend which allows me to
> select one payment method from the methods that got added to the one
> specific user. (the same applies to a form field for the frontend)
>
> It would be awesome if you could help me in that point. Thank you very
> much!
>
> On Feb 24, 7:10 pm, Timothy Kinney <timothyjkin...@gmail.com> wrote:
> > When you include the to_field, it tells Django that you want the
> foreignkey
> > to be the to_field on the CustomerProfile. It then looks for a field
> called
> > payment_id (following the foreignKey relationship). This is normal.
> >
> > If you remove the to_field, it will choose the primary key of
> > CustomerProfile which is probably an AutoField. Then it will look for
> > CustomerProfile_id which is a field that DOES exist.
> >
> > The point of the ForeignKey option is to link one model to another one
> *via
> > the primary key*. You don't link to a random field in the model, you
> always
> > link to the primary key.
> >
> > Does that make sense?
> >
> > -Tim
> >
> > On Tue, Feb 23, 2010 at 11:23 AM, django_is <
> festival.s...@googlemail.com>wrote:
> >
> > > Thank you for your response. But how would the Orders model field for
> > > payment look like?
> >
> > > Should it look like that:
> >
> > > payment = models.ForeignKey(CustomerProfile,
> > > related_name="order_customer_payment",verbose_name='Zahlungsart')
> >
> > > I don't understand how that should work. At the moment I am quite
> > > confused about what you mean.
> >
> > > Regards
> >
> > > On 23 Feb., 16:00, Daniel Roseman <dan...@roseman.org.uk> wrote:
> > > > On Feb 23, 11:56 am, django_is <festival.s...@googlemail.com> wrote:
> >
> > > > > Hmm ok. Assuming the use case above what would be the correct way
> to
> > > > > solve this problem? Especially to have the possibility to have one
> > > > > field in the Orders table that allows me to select one payment
> method
> > > > > of the methods which got added to the one specific user. Adding
> > > > > payment methods to each user happens in the CustomerProfile with
> the
> > > > > M2M relationship between the CustomerProfile model and the Payment
> > > > > model.
> >
> > > > > Here is the M2M relationship defined in the CustomerProfile:
> >
> > > > > payment = models.ManyToManyField(Payment,
> verbose_name='Zahlungsart')
> >
> > > > > This M2M relationship is working as expected. I just don't know how
> to
> > > > > get the payment methods inside the Orders model.
> >
> > > > > It would be great if you could help me with this.
> >
> > > > > Thank you very much.
> >
> > > > > Regards
> >
> > > > I don't know how I can make what I said in the previous message it
> any
> > > > clearer: you don't need the to_field.
> > > > --
> > > > DR.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> <django-users%2bunsubscr...@googlegroups.com<django-users%252bunsubscr...@googlegroups.com>
> >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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

Reply via email to