News for hackers. Stuff that matters.
Re:Django 1.7 Released by ubernostrum on Tuesday September 02, 2014 @07:45PM (#8260803)
You want this page:

https://docs.djangoproject.com/en/1.7/ref/models/fields/#mod...

In general:

Django's ForeignKey is equivalent to Rails' belongs_to.

Django's OneToOneField is equivalent to Rails' has_one.

Django's ManyToManyField is equivalent to Rails' has_and_belongs_to_many.

Also, in Django one generally only declares the relationship from one "side", unlike Rails where the relationship is declared on both "sides" (i.e., in Django one simply sets up a ForeignKey on A pointing to B, rather than placing relationship identifiers on both A and B).

The equivalent of ":through" is also available.

Django has GenericForeignKey as an equivalent to Rails' polymorphic associations.

Re:Django 1.7 Released by jsmeaton on Tuesday September 02, 2014 @08:26PM (#8260928)
Just to clarify a little:

> Also, in Django one generally only declares the relationship from one "side", unlike Rails where the relationship is declared on both "sides" (i.e., in Django one simply sets up a ForeignKey on A pointing to B, rather than placing relationship identifiers on both A and B).

That's because django will automatically add the reverse of the relation to B, so that you can access A through B. You can disable that functionality optionally though.