Opened 17 years ago

Closed 17 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: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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' ]

Change History (1)

comment:1 by James Bennett, 17 years ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top