tags:

views:

80

answers:

1

I know that I can use ForeignKey's related_name argument to control what the back-reference's name will be. But is it possible to avoid creating a back-reference completely?

(e.g., I have in Car a field ForeignKey(Person), and I don't want Person to have an attribute that leads backs to Car.)

+1  A: 

Why would you want to do this? You don't have to use it if you don't want to.

In any case, the back-reference is only a code shortcut - it's exactly equivalent to Car.objects.filter(person_id=person.id).

Daniel Roseman
I want to avoid possible clashes with existing attributes.
cool-RR
@cool-RR. Easy to do. Use the `related_name` attribute to give it some non-conflicting name. `related_name = 'some_non_conflicting_name'`.
S.Lott
That's an easy workaround, I agree. But I am looking for a way to have no back-reference at all.
cool-RR
@cool-RR: not having the back reference is impossible. In SQL, it exists. There's no way to stop it from existing.
S.Lott
Now that is an answer. You can post this as an answer and I'll accept it.
cool-RR