On 9/18/2010 3:23 PM, werefr0g wrote: > 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 ;) > That's a very clear explanation, and much more concise than the documentation. Congratulations. I also like your naming recommendation.
Of course, if you wanted the flexibility of an indefinite number of sides you would usually use a many-to-many relationship between Meals and Sides, perhaps with using a "through" table (? is that what they are called) to add one or more status columns to store further attributes of the relationship such as "post_main_course" / "with_main_course" (useful for searching). regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- 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.