Categories
Python Answers

How to write a __init__ function to be used in a Python Django model?

Spread the love

Sometimes, we want to write a init function to be used in a Python Django model.

In this article, we’ll look at how to write a init function to be used in a Python Django model.

How to write a init function to be used in a Python Django model?

To write a init function to be used in a Python Django model, we can pass in named arguments into the model class’ built in __init__ function.

For instance, we write

p = User(name="Fred", email="fred@example.com")

to create a User instance by passing in the name and email arguments.

Conclusion

To write a init function to be used in a Python Django model, we can pass in named arguments into the model class’ built in __init__ function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *