def is_field_nullable(model_class, field_name):
""" Helper function that checks if a field is nullable or not.
It also handles the case of foreign key fields with the '_id' suffix
"""
try:
return model_class._meta.get_field(field_name).null
except FieldDoesNotExist:
# Make sure it's not foreign key
if field_name.endswith('_id'):
return model_class._meta.get_field(field_name[:-3]).null
raise
评论列表
文章目录