It may make debugging a little harder, but it gives you a lot more flexibility in constructing objects.
Here's a factoryish method I wrote for testing: def create_teacher(textbook = None, user = None, start_state = None, explain_state = None, practice_state = None, finish_state = None, best_module = None, best_question = None, mediator = None, current_state = None): teacher = Teacher() teacher.textbook = textbook or create_textbook() teacher.user = user or create_user() start_state = start_state or create_start_state() teacher.start_state = start_state teacher.explain_state = explain_state or create_explain_state() teacher.practice_state = practice_state or create_practice_state() teacher.finish_state = finish_state or create_finish_state() teacher.best_module = best_module or create_best_module() teacher.best_question = best_question or create_best_question() teacher.mediator = mediator or create_mediator() teacher.current_state = start_state teacher.save() return teacher Now, I'm not saying I couldn't have initialized it in one line (with or without local variables), but it is pretty readable this way. On Oct 10, 6:39 am, Chris Withers <ch...@simplistix.co.uk> wrote: > Hi All, > > Assuming this model: > > class Month(models.Model): > month = models.DateField( > db_index=True, > verbose_name='Month' > ) > def __unicode__(self): > return unicode(self.month.strftime('%B %Y')) > > Now, I could have sworn this used to throw an error if I did: > > m = Month() > > ...because I haven't supplied a required field. But it no longer seems > to do so until .save() is called. > > Am I imagining things? > > This behaviour is suboptimal, here's an example why using the above model: > > >>> Month() > Traceback (most recent call last): > File "models.py", line 65, > in __unicode__ > return unicode(self.month.strftime('%B %Y')) > AttributeError: 'NoneType' object has no attribute 'strftime' > > :-( > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > -http://www.simplistix.co.uk --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---