bypassing reverse relation (related_name)

17 views
Skip to first unread message

Joe Holloway

unread,
Oct 17, 2007, 3:49:14 PM10/17/07
to django...@googlegroups.com
I'm finding that I have quite a few many-to-one relations that don't
really need the reverse relation to be expressed in the object model.
For example,

class Route(models.Model):
start = models.ForeignKey (Location)
destination = models.ForeignKey (Location)

The default related_name clashes here, so I must specify my own:

class Route(models.Model):
start = models.ForeignKey (Location, related_name='starting_points')
finish = models.ForeignKey (Location,

related_name='finishing_points')

In these cases, I always tend to come up with hokey names like above
since the reverse relation doesn't represent anything in the real
domain. Since I know I'll never need to walk the relation backwards,
so it seems like a decision I could avoid making altogether.

Is there a way to express that I don't need the reverse relation?

Thanks,
Joe

RajeshD

unread,
Oct 17, 2007, 4:12:20 PM10/17/07
to Django users
>
> Is there a way to express that I don't need the reverse relation?

No. Even if you don't need them, Django will want to dynamically endow
your Location objects with them. And, as you know, it can't do it if
two reverse relations have the same name.

Reply all
Reply to author
Forward
0 new messages