I'm trying to write a simple unit test for one of my models. I have two models - Build and Project. A Project has multiple Builds. I want to be able to create a build object, with an association to a Project. However I seem unable to do this unless I actually save the Project instance to the database - even if I have no intention of ever saving the build. For example:
>>> project = Project() >>> project.id = 4 >>> build = Build() >>> build.project = project >>> build.project Traceback (most recent call last): File "<console>", line 1, in ? File "c:\tools\python\python2.4\lib\site-packages\Django-0.95-py2.4.egg\django \db\models\fields\related.py", line 169, in __get__ rel_obj = self.field.rel.to._default_manager.get(**params) File "c:\tools\python\python2.4\lib\site-packages\Django-0.95-py2.4.egg\django \db\models\manager.py", line 67, in get return self.get_query_set().get(*args, **kwargs) File "c:\tools\python\python2.4\lib\site-packages\Django-0.95-py2.4.egg\django \db\models\query.py", line 213, in get raise self.model.DoesNotExist, "%s matching query does not exist." % self.mo del._meta.object_name DoesNotExist: Project matching query does not exist. In other persistence layers - Hibernate comes to mind - if I directly create the association as I have done here, I can query that association before persistence. If I have to create lots of fake data, and always hit the database it is going to add significant bloat to my unit testing. Any thoughts? -- sam http://www.magpiebrain.com/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---