Reputation: 3305
I have a model in django that points to another model. I want to test if it's set to something or not.
model.foreignkey = ForeignKeyField(...)
I want to test if this foreignkey is set or not - without actually fetching the foreign row's data (if the foreign key is set).
if model.foreignkey: # This line fetches data for
<dosomething>
Any help?
Upvotes: 1
Views: 957
Reputation: 2136
Test for model.foreignkey_id
Check out the docs: https://docs.djangoproject.com/en/dev/ref/models/fields/#database-representation
Upvotes: 4