prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Duplicate form fields in admin for user profiles
  As discussed here:
  
  https://groups.google.com/forum/#!topic/mezzanine-users/3QmiqfNZjUM
  
  
  </issue>
  <code>
  [start of mezzanine/accounts/admin.py]
  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 of mezzanine/accounts/admin.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
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"}]}