prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Duplicate form fields in admin for user profiles
  As discussed here:
  
  https://groups.google.com/forum/#!topic/mezzanine-users/3QmiqfNZjUM
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mezzanine/accounts/admin.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 
  3 from django.contrib import admin
  4 from django.contrib.auth import get_user_model
  5 from mezzanine.accounts import get_profile_model, ProfileNotConfigured
  6 
  7 from mezzanine.core.admin import SitePermissionUserAdmin
  8 from mezzanine.conf import settings
  9 from mezzanine.utils.email import send_approved_mail, send_verification_mail
  10 
  11 
  12 User = get_user_model()
  13 
  14 user_list_display = SitePermissionUserAdmin.list_display
  15 user_list_display += ("is_active", "date_joined", "last_login")
  16 
  17 
  18 class UserProfileAdmin(SitePermissionUserAdmin):
  19 
  20     list_display = user_list_display
  21 
  22     def save_model(self, request, obj, form, change):
  23         """
  24         If the ``ACCOUNTS_APPROVAL_REQUIRED`` setting is ``True``,
  25         send a notification email to the user being saved if their
  26         ``active`` status has changed to ``True``.
  27         If the ``ACCOUNTS_VERIFICATION_REQUIRED`` setting is ``True``,
  28         send a verification email instead.
  29         """
  30         must_send_verification_mail_after_save = False
  31         if change and settings.ACCOUNTS_APPROVAL_REQUIRED:
  32             if obj.is_active and not User.objects.get(id=obj.id).is_active:
  33                 if settings.ACCOUNTS_VERIFICATION_REQUIRED:
  34                     # Accounts verification requires an inactive account
  35                     obj.is_active = False
  36                     # The token generated by send_verification_mail()
  37                     # must match the _saved_ User object,
  38                     # so postpone send_verification_mail() until later
  39                     must_send_verification_mail_after_save = True
  40                 else:
  41                     send_approved_mail(request, obj)
  42         super(UserProfileAdmin, self).save_model(request, obj, form, change)
  43         if must_send_verification_mail_after_save:
  44             user = User.objects.get(id=obj.id)
  45             send_verification_mail(request, user, "signup_verify")
  46 
  47 
  48 try:
  49     class ProfileInline(admin.StackedInline):
  50         model = get_profile_model()
  51         can_delete = False
  52         template = "admin/profile_inline.html"
  53         extra = 0
  54     UserProfileAdmin.inlines += (ProfileInline,)
  55 except ProfileNotConfigured:
  56     pass
  57 
  58 
  59 if User in admin.site._registry:
  60     admin.site.unregister(User)
  61 admin.site.register(User, UserProfileAdmin)
  62
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/mezzanine/accounts/admin.py b/mezzanine/accounts/admin.py
  --- a/mezzanine/accounts/admin.py
  +++ b/mezzanine/accounts/admin.py
  @@ -51,6 +51,13 @@
           can_delete = False
           template = "admin/profile_inline.html"
           extra = 0
  +
  +        def get_min_num(self, request, obj=None, **kwargs):
  +            """This causes profile forms to be shown when editing but hidden
  +            when creating. If min_num is fixed at 1, Django's initial user
  +            creation form fails if the profile model has a required field."""
  +            return 0 if obj is None else 1
  +
       UserProfileAdmin.inlines += (ProfileInline,)
   except ProfileNotConfigured:
       pass
  
verification_info: {"golden_diff": "diff --git a/mezzanine/accounts/admin.py b/mezzanine/accounts/admin.py\n--- a/mezzanine/accounts/admin.py\n+++ b/mezzanine/accounts/admin.py\n@@ -51,6 +51,13 @@\n         can_delete = False\n         template = \"admin/profile_inline.html\"\n         extra = 0\n+\n+        def get_min_num(self, request, obj=None, **kwargs):\n+            \"\"\"This causes profile forms to be shown when editing but hidden\n+            when creating. If min_num is fixed at 1, Django's initial user\n+            creation form fails if the profile model has a required field.\"\"\"\n+            return 0 if obj is None else 1\n+\n     UserProfileAdmin.inlines += (ProfileInline,)\n except ProfileNotConfigured:\n     pass\n", "issue": "Duplicate form fields in admin for user profiles\nAs discussed here:\n\nhttps://groups.google.com/forum/#!topic/mezzanine-users/3QmiqfNZjUM\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom django.contrib import admin\nfrom django.contrib.auth import get_user_model\nfrom mezzanine.accounts import get_profile_model, ProfileNotConfigured\n\nfrom mezzanine.core.admin import SitePermissionUserAdmin\nfrom mezzanine.conf import settings\nfrom mezzanine.utils.email import send_approved_mail, send_verification_mail\n\n\nUser = get_user_model()\n\nuser_list_display = SitePermissionUserAdmin.list_display\nuser_list_display += (\"is_active\", \"date_joined\", \"last_login\")\n\n\nclass UserProfileAdmin(SitePermissionUserAdmin):\n\n    list_display = user_list_display\n\n    def save_model(self, request, obj, form, change):\n        \"\"\"\n        If the ``ACCOUNTS_APPROVAL_REQUIRED`` setting is ``True``,\n        send a notification email to the user being saved if their\n        ``active`` status has changed to ``True``.\n        If the ``ACCOUNTS_VERIFICATION_REQUIRED`` setting is ``True``,\n        send a verification email instead.\n        \"\"\"\n        must_send_verification_mail_after_save = False\n        if change and settings.ACCOUNTS_APPROVAL_REQUIRED:\n            if obj.is_active and not User.objects.get(id=obj.id).is_active:\n                if settings.ACCOUNTS_VERIFICATION_REQUIRED:\n                    # Accounts verification requires an inactive account\n                    obj.is_active = False\n                    # The token generated by send_verification_mail()\n                    # must match the _saved_ User object,\n                    # so postpone send_verification_mail() until later\n                    must_send_verification_mail_after_save = True\n                else:\n                    send_approved_mail(request, obj)\n        super(UserProfileAdmin, self).save_model(request, obj, form, change)\n        if must_send_verification_mail_after_save:\n            user = User.objects.get(id=obj.id)\n            send_verification_mail(request, user, \"signup_verify\")\n\n\ntry:\n    class ProfileInline(admin.StackedInline):\n        model = get_profile_model()\n        can_delete = False\n        template = \"admin/profile_inline.html\"\n        extra = 0\n    UserProfileAdmin.inlines += (ProfileInline,)\nexcept ProfileNotConfigured:\n    pass\n\n\nif User in admin.site._registry:\n    admin.site.unregister(User)\nadmin.site.register(User, UserProfileAdmin)\n", "path": "mezzanine/accounts/admin.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nfrom django.contrib import admin\nfrom django.contrib.auth import get_user_model\nfrom mezzanine.accounts import get_profile_model, ProfileNotConfigured\n\nfrom mezzanine.core.admin import SitePermissionUserAdmin\nfrom mezzanine.conf import settings\nfrom mezzanine.utils.email import send_approved_mail, send_verification_mail\n\n\nUser = get_user_model()\n\nuser_list_display = SitePermissionUserAdmin.list_display\nuser_list_display += (\"is_active\", \"date_joined\", \"last_login\")\n\n\nclass UserProfileAdmin(SitePermissionUserAdmin):\n\n    list_display = user_list_display\n\n    def save_model(self, request, obj, form, change):\n        \"\"\"\n        If the ``ACCOUNTS_APPROVAL_REQUIRED`` setting is ``True``,\n        send a notification email to the user being saved if their\n        ``active`` status has changed to ``True``.\n        If the ``ACCOUNTS_VERIFICATION_REQUIRED`` setting is ``True``,\n        send a verification email instead.\n        \"\"\"\n        must_send_verification_mail_after_save = False\n        if change and settings.ACCOUNTS_APPROVAL_REQUIRED:\n            if obj.is_active and not User.objects.get(id=obj.id).is_active:\n                if settings.ACCOUNTS_VERIFICATION_REQUIRED:\n                    # Accounts verification requires an inactive account\n                    obj.is_active = False\n                    # The token generated by send_verification_mail()\n                    # must match the _saved_ User object,\n                    # so postpone send_verification_mail() until later\n                    must_send_verification_mail_after_save = True\n                else:\n                    send_approved_mail(request, obj)\n        super(UserProfileAdmin, self).save_model(request, obj, form, change)\n        if must_send_verification_mail_after_save:\n            user = User.objects.get(id=obj.id)\n            send_verification_mail(request, user, \"signup_verify\")\n\n\ntry:\n    class ProfileInline(admin.StackedInline):\n        model = get_profile_model()\n        can_delete = False\n        template = \"admin/profile_inline.html\"\n        extra = 0\n\n        def get_min_num(self, request, obj=None, **kwargs):\n            \"\"\"This causes profile forms to be shown when editing but hidden\n            when creating. If min_num is fixed at 1, Django's initial user\n            creation form fails if the profile model has a required field.\"\"\"\n            return 0 if obj is None else 1\n\n    UserProfileAdmin.inlines += (ProfileInline,)\nexcept ProfileNotConfigured:\n    pass\n\n\nif User in admin.site._registry:\n    admin.site.unregister(User)\nadmin.site.register(User, UserProfileAdmin)\n", "path": "mezzanine/accounts/admin.py"}]}