[Python] Writing a __init__ function to be used in django model

Discussão em 'Python' iniciado por Stack, Agosto 8, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write an __init__ function for one of my models so that I can create an object by doing:

    p = User('name','email')


    When I write the model, I have:

    def __init__(self, name, email, house_id, password):
    models.Model.__init__(self)
    self.name = name
    self.email = email


    This works and I can save the object to the database, but when I do User.objects.all(), it doesn't pull anything up unless I take out my __init__ function. Any ideas?

    Continue reading...

Compartilhe esta Página