'Django-python coding explanation
What is static method and how can we explain the below code ?
@staticmethod
def get_model(**kwargs):
try:
return Model.objects.get(**kwargs)
except Model.DoesNotExist:
return
Solution 1:[1]
A staticmethod is a function not bound to an object, but is encapsulated within it ( typically to reduce outer namespace clutter, or eliminate any need to import it). It doesn't have the first self argument that a normal object method does.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nigel222 |
