This might help maybe: https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey.allow_unsaved_instance_assignment
On Thursday, 16 July 2015 12:21:30 UTC+1, Roland Swingler wrote: > > Hi all, > > I've very recently come to to Django from a rails background, and > struggling to do unit testing of Django models without saving to the > database as I'm used to in Rails. Lets say you have 2 linked models, for > example User and UserProfileDetails, then in my tests I want to set up the > structure and not save any of it: > > user = User() > user.profile_details = UserProfileDetails() > ... > # stuff that tests non-persistence related functionality > > But I don't seem to be able to do this, because it will raise a > RelatedObjectDoesNotExist error, saying UserProfileDetails has no user. > Obviously I can get around this by saving the user first, but if I want to > not touch the database in tests is there any way I can achieve this? > > (also apologies if this has been asked before - I did a quick search of > the archives and couldn't find anything). > > Thanks in advance, > Roland > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6fcb1249-6aab-4af6-b583-57ad18364419%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

