Lazy relation not resolved when get_defaults get called

14 views
Skip to first unread message

Ghislain Leveque

unread,
Oct 7, 2014, 4:41:06 AM10/7/14
to django...@googlegroups.com
I'm in a situation where the get_defaults method on the RelatedField class is called but self.rel.to as not been resolved yet and is still a string. I'm using Django 1.6.6 and I cannot upgrade easily (big number of systems in production).

Some important stuff :

- the problem appears when I create a new object inside a py.test fixture
- if I create the same object inside the shell_plus I have no problem

Here is an extract of my model (foreigns A and B are mandatory, C is not) :


class MyModel(models.Model):

   
fielda = models.ForeignKey(
       
'otherapp.modela', db_column='fielda')
   
fieldb = models.ForeignKey(
       
'otherapp.modelb', db_column='fieldb')
   
fieldc = models.ForeignKey(
       
'otherapp.modelc', db_column='fieldc',
       
null=True, blank=True)


and here is how I use it :


# A is an instance of otherapp.modela
# B is an instance of otherapp.modelb
my_object
= MyModel(fielda=A, fieldb=B)




Is there anything more I can provide to help ?

Thank you

Collin Anderson

unread,
Oct 7, 2014, 12:30:39 PM10/7/14
to django...@googlegroups.com
I use this to fix that problem. Run it before you use your first model.

from django import models
models
.get_models()

Reply all
Reply to author
Forward
0 new messages