#37147: Empty form for inlines breaks when using db_default on primary key field
-------------------------------------+-------------------------------------
     Reporter:  Mariusz Felisiak     |                    Owner:  Mariusz
                                     |  Felisiak
         Type:  Bug                  |                   Status:  assigned
    Component:  Forms                |                  Version:  6.0
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

 The following fixes this issue for me:
 {{{#!diff
 diff --git a/django/forms/widgets.py b/django/forms/widgets.py
 index f401896b60..140bd3e395 100644
 --- a/django/forms/widgets.py
 +++ b/django/forms/widgets.py
 @@ -343,7 +343,9 @@ class Widget(metaclass=MediaDefiningClass):
          """
          Return a value as it should appear when rendered in a template.
          """
 -        if value == "" or value is None:
 +        from django.db.models.expressions import DatabaseDefault
 +
 +        if value == "" or value is None or isinstance(value,
 DatabaseDefault):
              return None
          if self.is_localized:
              return formats.localize_input(value)
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37147#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019ea1c1a75a-224fe236-94cc-4235-a7e2-426c7ee0accd-000000%40eu-central-1.amazonses.com.

Reply via email to