Skip to content

Commit

Permalink
Make non-null fields required
Browse files Browse the repository at this point in the history
  • Loading branch information
cdman committed May 21, 2018
1 parent 8ff8e98 commit ef12aa3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Changes in version 1.1.0
========================

* Added support for Django 2.1 and dropped support for Django < 1.11.
* `.save()`, `.create()`, etc. now raise IntegrityError if `null` is not True
and no default value was specified (like built-in fields do).

Changes in version 1.0.0
========================
Expand Down
1 change: 1 addition & 0 deletions src/picklefield/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class PickledObjectField(models.Field):
can still do lookups using None). This way, it is still possible to
use the ``isnull`` lookup type correctly.
"""
empty_strings_allowed = False

def __init__(self, *args, **kwargs):
self.compress = kwargs.pop('compress', False)
Expand Down
7 changes: 6 additions & 1 deletion src/picklefield/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from datetime import date

import django.db
from django.core import serializers
from django.db import models
from django.test import TestCase
Expand Down Expand Up @@ -62,7 +63,7 @@ def testDataIntegrity(self):

# Make sure the default value for default_pickled_field gets stored
# correctly and that it isn't converted to a string.
model_test = TestingModel()
model_test = TestingModel(pickle_field=1, compressed_pickle_field=1)
model_test.save()
model_test = TestingModel.objects.get(id__exact=model_test.id)
self.assertEqual((D1, S1, T1, L1), model_test.default_pickle_field)
Expand Down Expand Up @@ -197,3 +198,7 @@ def testNoCopy(self):
compressed_pickle_field='Copy Me',
non_copying_field='Dont copy me'
)

def testAllNonNullFieldsNeedToBeSetForSave(self):
with self.assertRaises(django.db.IntegrityError):
MinimalTestingModel.objects.create()

0 comments on commit ef12aa3

Please sign in to comment.