question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it easier to use a custom user model with user create/edit/account settings forms

See original GitHub issue

Is your proposal related to a problem?

When a project creates a custom user model where first_name and last_name are optional, the Wagtail forms still display the fields as being required. In order to make the form fields optional, the developer must override the WAGTAIL_USER-EDIT_FORM and WAGTAIL_USER_CREATION_FORM with custom-defined models. They must also somehow override the Account Settings form for the user profile section (which I am still not clear how to do).

At the very least, the process is somewhat ambiguous, despite the available documentation:

Describe the solution you’d like

Ideally, the forms would introspect the custom user model to determine whether the fields are required. Furthermore, it might be good to simplify the development process and just allow the user to specify a list of fields to render in the forms rather than creating three custom forms (create/edit/account settings).

Describe alternatives you’ve considered

The documentation could be improved around how to customize the user account settings form.

Additional context

We have a downstream issue where it became apparent how confusing it is to make changes to the user create and edit forms, as well as a follow-up to split the work:

I am also trying to customize the user account settings form to make the fields optional and finding myself at a loss as to how to proceed.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
heldercocommented, Nov 8, 2021

No, not the docs. The current wagtail.admin.forms.account.NameEmailForm would have to be adapted to support settings.WAGTAIL_USER_CUSTOM_FIELDS and django.contrib.auth.base_user.AbstractBaseUser.REQUIRED_FIELDS.

0reactions
rikvacommented, Oct 6, 2022

Almost the same problem here. Found this issue page by googling “NameEmailSettingsPanel”.

In my case the custom user model contains no name fields. I’ve managed to remove those fields from the user creation and admin forms using:

class CustomUserCreationForm(UserCreationForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        del self.fields["first_name"]
        del self.fields["last_name"]

Unfortunately I have not succeeded in removing them from the user account form.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Editing User Account Properties (Django custom user model)
Watch the course: https://codingwithmitch.com/courses/real-time-chat-messenger/
Read more >
Creating a Custom User Model in Django - TestDriven.io
This post explains step-by-step how to create a custom User model in Django so that an email address can be used as the...
Read more >
How to Create a Custom Django User Model - Blog Post
1. Create a new app · 2. Create the Custom User Model in models.py · 3. Create the User model manager · 4....
Read more >
Django Best Practices: Custom User Model | LearnDjango.com
Creating our initial custom user model requires four steps: ... In settings.py we'll add the accounts app and use the AUTH_USER_MODEL config to ......
Read more >
Customizing authentication in Django
contrib.auth.models.AbstractUser and add your custom profile fields, although we'd recommend a separate model as described in Specifying a custom user ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found