Reputation: 4125
I would like to have a field, that is simply a copy of another field.
Class Foo(models.Model):
bool = models.BooleanField(default=False)
class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bar')
copy = foo.bool # i would want this to be equal to bar.foo.bool
Upvotes: 1
Views: 65
Reputation: 599600
I think you are looking for a property:
class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bar')
@property
def copy(self):
return self.foo.bool
Note, even for your real use case this is pretty pointless, you can always access the image field via the FK.
Upvotes: 1