B
B
Boldy2014-10-22 17:41:42
Django
Boldy, 2014-10-22 17:41:42

How to create custom user model in django?

How to create a model of a user who, when registering, needs to specify a login, password, as well as the login of the person who invited (autocomplete from the column in the table)? How is it better to implement authentication - through the admin panel or create a separate page for ordinary "mortal" users? Why?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bromzh, 2014-10-22
@Boldy

In the new jang, you can customize the user model.
Ask Google moderators to remove your search ban.
A concise retelling, given that you are creating an application from scratch, and not migrating from a created application with a ready-made base and users:

class Article(models.Model):
    author = models.ForeignKey(settings.AUTH_USER_MODEL)

And you do the same for signals:
def post_save_receiver(signal, sender, instance, **kwargs):
    pass

post_save.connect(post_save_receiver, sender=settings.AUTH_USER_MODEL)

  • You create a user model in which you specify an identifier field (for example, it can be a name field, or an email field, or some other).
    class MyUser(AbstractBaseUser):
        identifier = models.CharField(max_length=40, unique=True)
        ...
        USERNAME_FIELD = 'identifier'

    In the same model, you prescribe the fields necessary for registration:
    class MyUser(AbstractBaseUser):
        ...
        date_of_birth = models.DateField()
        height = models.FloatField()
        ...
        REQUIRED_FIELDS = ['date_of_birth', 'height']

    You also need to override some methods and fields if necessary (the docs say which ones)
  • You need to create new forms for your user and customize the admin class, taking into account your new fields
  • ???
  • PROFIT
  • D
    DjangoIsFree, 2014-10-23
    @DjangoIsFree

    www.lasolution.be/blog/creating-custom-user-model-...
    here look at the last example to register a new model in the admin panel: djbook.ru/examples/6

    Didn't find what you were looking for?

    Ask your question

    Ask a Question

    731 491 924 answers to any question