Code

Opened 6 years ago

Closed 6 years ago

#6762 closed (duplicate)

TabularInline in Admin breaks when fields have default values

Reported by: ingenieroariel Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: inline, default, save, newforms-admin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In the following code, everytime the save button is hit in the parent change_form it complains about empty inline model.
I guess it is because default values are assigned to some fields and it tries to save the partially empty objects.

Here is a simple example that works ok, without the default

from django.db import models
from django.contrib import admin
# Create your models here.

class Parent(models.Model):
    name=models.CharField(max_length=20)

CHOICES = (

        ('choice', 'choice'),

        ('choice1', 'choice1'),

    ) 
class Son(models.Model):
    name=models.CharField(max_length=20)
    parent=models.ForeignKey(Parent)
    choice=models.CharField(max_length=20, choices=CHOICES, default='choice')

class SonModelInline(admin.TabularInline):
    model = Son
    extra = 1

class ParentOptions(admin.ModelAdmin):
    inlines = [SonModelInline]

admin.site.register(Son)
admin.site.register(Parent, ParentOptions)

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by Karen Tracey <kmtracey@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Dup of #5878, I believe.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.