Writing a __init__ function to be used in django model

Relying on Django’s built-in functionality and passing named parameters would be the simplest way to go.

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

But if you’re set on saving some keystrokes, I’d suggest adding a static convenience method to the class instead of messing with the initializer.

# In User class declaration
@classmethod
def create(cls, name, email):
  return cls(name=name, email=email)

# Use it
p = User.create("Fred", "fred@example.com")

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.