1đź‘Ť
Pk
is a property that usually resolves to id
. There is no magic other than that.
So the only difference between the two statements is how Python treats them. The first one explicitely tests if pk
is None, whereas the second one will pass for any “falsy” value of pk
.
Note that pk
shouldn’t usually evaluate to False
unless the model instance is not saved to the database, so in practice the two statements should be pretty much equivalent.
- [Django]-Django autocomplete_fields doesn't work in TabularInline (but works in StackedInline)
- [Django]-Attribute Cache in Django – What's the point?
- [Django]-How can I omit time at HTML {{ post.published_date }} tag?
- [Django]-How to run django app binded with gunicorn?
- [Django]-Deleting files associated with model – django
Source:stackexchange.com