﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16511	Problem with import and GFK	rjdg@…	nobody	"Hello,

I have an error ""Cannot import name <model name>"" and find out why. It seems a bit strange so I report it as a bug.

Description:

We have two apps: x and y. And two Models: A (in x) and B (in y)

B has a generic foreign key
A has generic relation to B

I added this line to y.models:
from x.models import A

And Django raises error: ""Cannot import name A"" when I try to use python manage.py commands.
I needed this import line because I wanted to add third model - C in y.models, which would have a foreignkey to A

I've tested it also in a new empty django project and it works (hmm, in fact doesn't work) exactly that way.

Source:
x.models:
from django.db import models
from django.contrib.contenttypes import generic                                 
from y.models import B

class A:
  b_rel = generic.GenericRelation(B)

y.models:
from django.db import models
from django.contrib.contenttypes import generic                                 
from x.models import A

class B:
  content_object = generic.GenericForeignKey()

class C:
  a = models.ForeignKey(A)

Removing import of A (and respectivly, the foreignkey to A in C) fixes the problem. I think it shouldn't be like that. I don't want to split application y to store C in separate file.

If it's a known problem I'm sorry, I've searched.
"	Bug	closed	contrib.contenttypes	1.3	Normal	invalid	import,genericforeignkey,genericrelation		Unreviewed	0	0	0	0	0	0
