0

Consider we have a model like this

class A(Models.model): .... class B(A): .... x = models.ForeignKey(B, related_name="rn1") .... class C(A): .... x = models.ForeignKey(B, related_name="rn2") .... 

Observe that both fields above define the same thing with just a difference in the related_name. I feel that this part can also be shifted to class A somehow and just change the related_name in children.

Can this be done or should I use copies of the same code with different related_name?

1
  • If it were ManyToManyField then your thought might work, but since it is a ForeignKey, it is a 1:n relation, and the reverse would not work the same way. Commented Jul 7, 2014 at 14:43

1 Answer 1

1

Nope.

models.ForeignKey() creates a new object from Foreign key class.

Maybe u can do something in init but this causes more code block and some third party tools like south may give error.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.