go-best-practice | 100 projects in various categories | Learning library
kandi X-RAY | go-best-practice Summary
kandi X-RAY | go-best-practice Summary
Trying to complete over 100 projects in various categories in golang.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of go-best-practice
go-best-practice Key Features
go-best-practice Examples and Code Snippets
Community Discussions
Trending Discussions on go-best-practice
QUESTION
I am trying to write a class that takes an instance of a Model from my app as an argument in its __init__
.
While reading up on the subject, I stumbled upon this quesiton: django: best practice way to get model from an instance of that model which argues that simply using type(instance)
would be the best way to go.
As tempting as it may be to use this right away, wouldn't using isinstance(instance, model)
be a better solution?
Say, for example (from my own code):
ANSWER
Answered 2020-Sep-28 at 06:01From isinstance
documentation
Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. If object is not an object of the given type, the function always returns False. If classinfo is a tuple of type objects (or recursively, other such tuples), return True if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised.
This would mean that if you have model that is subclass of another one that they will both be marked as instance of superclass
For example :
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go-best-practice
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page