Skip to content

Commit

Permalink
Only validate foreign key if required or data is present.
Browse files Browse the repository at this point in the history
  • Loading branch information
timster committed Mar 21, 2016
1 parent a74294f commit 53b4da9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion peewee_validates.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def clean(self, value, data):
raise ValidationError('unique')

# Validate foreign key reference (and return the instance).
if isinstance(self.field, peewee.ForeignKeyField):
if (value or not self.field.null) and isinstance(self.field, peewee.ForeignKeyField):
try:
return self.field.rel_model.get(self.field.to_field == value)
except self.field.rel_model.DoesNotExist:
Expand Down

0 comments on commit 53b4da9

Please sign in to comment.