How to change default django User model to fit my needs?

前端 未结 5 1751
孤独总比滥情好
孤独总比滥情好 2021-01-01 23:25

The default Django\'s User model has some fields, and validation rules, that I don\'t really need. I want to make registration as simple as possible, i.e. requi

5条回答
  •  旧巷少年郎
    2021-01-02 00:17

    The Django User model is structured very sensibly. You really don't want to allow arbitrary characters in a username, for instance, and there are ways to achieve email address login, without hacking changes to the base model.

    To simply store additional information around a user account, Django supports the notion of user profiles. While you don't need to rely on the built in support to handle this, it is a convention that is commonly followed and it will allow you to play nice with the reusable Django apps that are floating around in the ether. For more information, see here.

    If you want to actually modify the core User model but also "play nice" with reusable apps that rely on it, you're opening a bit of a Pandora's Box. Developers make base assumptions about how the core library is structured, so any changes may cause unexpected breakage. Nonetheless, you can monkeypatch changes to the base model, or branch a copy of Django locally. I would discourage the latter, and only recommend the former if you know what you're doing.

提交回复
热议问题