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> > . > 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.