5
When using the foreign field in a model, Django creates two fields: One for the actual link, and one that references the other model.
class A(Model):
i = IntegerField()
class B(Model):
a = ForeignKey(A)
In B
there is now two fields: a
and a_id
. a_id
is the unique id as stored in the database, while a
can be used to directly access the fields in A
, like this:
b = B.objects.get(...)
b.a.i = 5; # Set the field of A
b.a.save() # Save A
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
- [Django]-How to change status of JsonResponse in Django
- [Django]-Session data corrupted in django
Source:stackexchange.com