That cleared it up, thanks! Great information which will definitely
help me in the future.

On Nov 6, 3:52 am, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Nov 6, 10:27 am, Håkan Waara <[EMAIL PROTECTED]> wrote:
>
> > 6 nov 2008 kl. 10.05 skrev Daniel Roseman:
>
> > > The problem is not with the imports (you were fine with the original
> > > method - in fact I'd recommend it, to avoid any future problems with
> > > circular imports), but with the __unicode__ methods. As the error
> > > states, you're referring to the related object's class, not the
> > > instance.
>
> > I've avoided using strings for referring to other models in my project  
> > because I prefer a explicity and a runtime error as soon as possible,  
> > if the model changes name etc. Will referring to other models using  
> > strings give the same sort of safety?
>
> > /Håkan
>
> Don't know, but consider this:
>
> app_a/models.py:
>
> from app_b import ModelB
> class ModelA(models.Model):
>     name = models.CharField(max_length=10)
>
> class ModelC(models.Model):
>     name = models.CharField(max_length=10)
>     model_b = models.ForeignKey(ModelB)
>
> app_b/models.py:
>
> from app_a import ModelA
> class ModelB(models.Model):
>     name = models.CharField(max_length=10)
>     model_a = models.ForeignKey(ModelA)
>
> Result: Cannot import ModelA.
> There are various ways round this, but the easiest is just to drop the
> imports and use the string format:
> models.ForeignKey('app_b.ModelB')
> --
> DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to