Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable django related_name for a specific field?

Tags:

django

Example:

class Route(models.Model):
    last_waypoint_visited = models.ForeignKey('WayPoint')

class WayPoint(models.Model):
    route = models.ForeignKey(Route)

Since WayPoint already has a reference to Route through the route field, I don't really need the field last_waypoint_visited to generate a back reference to Route.

Is it possible do just disable the back reference creation for the "last_waypoint_visited" field?

like image 544
Leandro Lima Avatar asked Jan 09 '15 14:01

Leandro Lima


1 Answers

Yes, disabling backward relations is a documented feature:

last_waypoint_visited = models.ForeignKey('WayPoint', related_name='+')
like image 116
catavaran Avatar answered Nov 02 '22 07:11

catavaran