Code

Opened 7 years ago

Closed 7 years ago

#4204 closed (invalid)

Admin interface attempts to save null to fields not in 'fields': list

Reported by: david@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Admin appears to attempt to save NULL to fields that are not shown in the Admin interface?

Here is an example model that doesn't work. Trying to update a record using Admin will crash with

"Data truncated; NULL supplied to NOT NULL column 'nlgroup' at row 1"

David

from django.db import models
 
# Create your models here.
class People(models.Model):
  def __str__(self):
        return '%s, %s (%s)' % (self.family, self.givens, self.orgname)
# copied from spreadsheet
  peopcode = models.CharField(maxlength=8, verbose_name="People Code", unique= True, editable= False)
  family = models.CharField(maxlength=25, verbose_name="Family", blank= True)
  givens = models.CharField(maxlength=25, verbose_name="Givens", blank= True)
  nlgroup = models.CharField(maxlength=3, verbose_name="Newsletter Group", blank= True)
  paddress1 = models.CharField(maxlength=80, verbose_name="Postal Address Line 1", blank= True)
  paddress2 = models.CharField(maxlength=80, verbose_name="Postal Address Line 2", blank= True)
  email = models.EmailField(verbose_name="Email", null = True, blank= True)
  orgname = models.CharField(maxlength=40, verbose_name="Organisation Name", blank= True)
  class Admin:
    fields = (
      (None, {
        'fields': (('family', 'givens', 'orgname'), 'email')
      }),
      ('Advanced options', {
        'classes': 'collapse',
        'fields' : ('paddress1', 'paddress2')
      }),
    ) 
  class Meta:
    ordering = ['family', 'givens', 'orgname' ]

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by ubernostrum

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

If you need to have a value for a field before hitting the DB, you need to either show it in the admin and require input, or have code in a custom save method fill in a value before the object is saved to the DB.

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.