Saturday, September 18, 2010

Re: Relationship question: What do I do wrong?

Hello,

I was quite laconic previously in order to spare you my "english". Sorry if you found this rude.

Well, you describe the relashionship from one model perspective (Meal) while setting your field (side1).By setting Field side1 in Meal as models.ForeignKey, you state that a Meal has a relationship to one Side as side1 but you also explicitly state that one Side can be related to many Meal through this relashionship.

If my_meal is your Meal instance, you'll use my_meal.side1 to reach related Side through side1 relashionship. With my_side as a Side instance, you'll use my_side.meal_set to reach all Meal related to my_side regarding the same relashionship.

Now, taking side2 Field in account, you can use my_meal.side2 but you can no longer use my_side.meal_set: you cannot distinguish which relashionship is implied this way. The related_name parameters allows you to make that distinction. Here you can place 'with main course' and 'post main course' and, by the way, I think you should name fields with_main_course_side and post_main_course_side or alike.

You'll find at http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects more details with an explanation of the nature of side1.meal_set object type's nature _ in better english ;)

Regards

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate