Skip to content
This repository
Browse code

Small fixes for compat

  • Loading branch information...
commit 619a81db739a16733d8c343cf26fecfbdb38f1e6 1 parent e981652
Charles Leifer authored October 09, 2012

Showing 1 changed file with 3 additions and 1 deletion. Show diff stats Hide diff stats

  1. 4  peewee.py
4  peewee.py
@@ -317,6 +317,7 @@ def add_to_class(self, model_class, name):
317 317
         self.name = name
318 318
         self.model_class = model_class
319 319
         self.db_column = self.db_column or self.name
  320
+        self.verbose_name = self.verbose_name or re.sub('_+', ' ', name).title()
320 321
 
321 322
         model_class._meta.fields[self.name] = self
322 323
         model_class._meta.columns[self.db_column] = self
@@ -489,7 +490,7 @@ def __init__(self, field, rel_model):
489 490
 
490 491
     def get_object_or_id(self, instance):
491 492
         rel_id = instance._data.get(self.att_name)
492  
-        if rel_id:
  493
+        if rel_id or self.att_name in instance._obj_cache:
493 494
             if self.att_name not in instance._obj_cache:
494 495
                 obj = self.rel_model.get(self.rel_model._meta.primary_key==rel_id)
495 496
                 instance._obj_cache[self.att_name] = obj
@@ -540,6 +541,7 @@ def add_to_class(self, model_class, name):
540 541
         self.name = name
541 542
         self.model_class = model_class
542 543
         self.db_column = self.db_column or '%s_id' % self.name
  544
+        self.verbose_name = self.verbose_name or re.sub('_+', ' ', name).title()
543 545
 
544 546
         model_class._meta.fields[self.name] = self
545 547
         model_class._meta.columns[self.db_column] = self

0 notes on commit 619a81d

Please sign in to comment.
Something went wrong with that request. Please try again.