0

Apologies if this is a really stupid question...

Say I have a model and manager, like this,

class TestModel_1Manager (models.Manager):
    def create (self, tk)
        m = self.model(test_key=tk)

class TestModel_1 (models.Model):
    test_key = models.ForeignKey ('TestModel_2')
    objects = TestModel_1Manager

Several questions:

  1. Is this right at all?

  2. If this is right, then the models.ForeignKey field does NOT take an object? Just a simple id integer is fine? That is, I don't need to do this: m = self.model(test_key=TestModel_1.objects.get(id=tk)) or something like that?

Maybe I don't quite get what this models.ForeignKey actually is... an integer or some object reference?

Thanks!!

EDIT: just found this post Django: Set foreign key using integer?, wondering if it's relevant...

Community
  • 1
  • 1
reedvoid
  • 1,203
  • 3
  • 18
  • 34

1 Answers1

1

ForeignKey is an abstraction. The field's value is another object, but it is represented in the table as the value of the PK of that object.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358