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 On 23 Feb., 12:32, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Feb 23, 10:21 am, django_is <festival.s...@googlemail.com> wrote: > > > > > Hello. > > > I got the following use case: > > > ---- > > Customer has Payment methods (many to many) > > Customer is a Proxy class of User and Customer has a profile which is > > connected with AUTH_PROFILE_MODULE to the User/Customer. > > > Each order has one customer and one payment method (one payment method > > from the methods that are added to the Customer) > > > To get the payment method inside my Order I got the following inside > > the Order model: > > > payment = models.ForeignKey(Customer, to_field="payment", > > related_name="order_customer_payment",verbose_name='Zahlungsart') > > ----- > > > Well now I am getting "django.db.models.fields.FieldDoesNotExist: > > Customer has no field named 'payment'". I understand why I'm getting > > this since the "payment" field is inside the CustomerProfile. > > > I have also tried to do: > > > payment = models.ForeignKey(CustomerProfile,to_field="payment", > > related_name="order_customer_payment",verbose_name='Zahlungsart') > > > But this leads to the following error while syncdb: > > > "Failed to install index for my_app_name.Orders model: table > > my_app_name_orders has no column named payment_id" > > > Is there a possibility to solve the problem? > > Why do you need the to_field at all? It certainly doesn't make sense > to point it at a ManyToMany field, since that doesn't correspond to a > database field directly on the model table. But there doesn't seem to > be any reason to use it at all here. > -- > 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. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.