Thank you for your kind reply @naveenkumar...@gmail.com.

Here is the way that we found to solve this issue.

Company App > models.py
```python3
    country              = models.ForeignKey('login.Country',
                                            on_delete=models.SET_NULL,
                                            null=True,
                                            blank=False)
```
The Project structure was quite large so did not find appropriate to share all 
of that here.
Therefore shared a snippet.

Regards
Pradyum


From: "django-rest-framework@googlegroups.com" 
<django-rest-framework@googlegroups.com>
Reply to: "django-rest-framework@googlegroups.com" 
<django-rest-framework@googlegroups.com>
Date: Thursday, 24 September 2020 at 3:16 PM
To: Digest recipients <django-rest-framework@googlegroups.com>
Subject: Digest for django-rest-framework@googlegroups.com - 3 updates in 2 
topics

django-rest-framework@googlegroups.com<%20%20https:/groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/django-rest-framework/topics>
Google 
Groups<https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
[Image removed by 
sender.]<https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
Topic digest
View all 
topics<%20%20https:/groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/django-rest-framework/topics>
·         Attribute Error in Django model Foreign Key - 2 Updates
·         Create an invitation link using django rest framework? - 1 Update
Attribute Error in Django model Foreign Key 
<http://groups.google.com/group/django-rest-framework/t/16b95088fdd6bda2?utm_source=digest&utm_medium=email>
Pradyum Gupta <pradyum.gup...@gmail.com>: Sep 24 09:00AM

In My Django Project, there are two apps: Login and Company

The **error that am receiving** in this is
```python
AttributeError: module 'login.models' has no attribute 'Country'
```

*Company App* > models.py
```python
from django.db import models
from login import models as LM

class CompanyProfile(models.Model):
full_name = models.CharField(max_length=255,
unique = True)

country = models.ForeignKey(LM.Country,
on_delete=models.SET_NULL,
null=True,
blank=False)

state = models.ForeignKey(LM.State,
on_delete=models.SET_NULL,
null=True,
blank=False)
def __str__(self):
return self.full_name
```

*Login App* > models.py
````python

class Country(models.Model):
"""List of Country"""
name = models.CharField(max_length=50, unique= True, default='None')
code = models.CharField(max_length=2, unique= True, primary_key=True, default 
='NA')

def __str__(self):
return str(self.code)

class State(models.Model):
"""List fo State"""
region = models.CharField(max_length = 255, unique = True, primary_key=True, 
default='None')
country = models.ForeignKey(Country, on_delete=models.SET_NULL, null=True, 
blank=False, default ='NA')

def __str__(self):
return self.region

````

Here is test to check that weather is login is getting imported or not
```python
def test_import():
try:
# import pdb; pdb.set_trace()
importlib.find_loader('LM.Country')
found = True
except ImportError:
found = False
print(found)
```

Answer is received stands to be True
```
python3 manage.py shell
>>> test_import()
True
```

Now on other stackoverflow blogs i checked i thought it could be of 
```Circlular Import```
But i have already fixed that still am getting this error?

Thanks in Advance
Regards

PS: I have also asked the same question here 
https://stackoverflow.com/q/64042995/7999665
naveen Kumar <naveenkumar...@gmail.com>: Sep 24 03:07PM +0530

i thinks it will be helpful if you place screenshots of you project file
structure as you mentioned along with models, so that people can easily
trace out the issue.....

On Thu, Sep 24, 2020 at 2:30 PM Pradyum Gupta <pradyum.gup...@gmail.com>
wrote:

Back to top
Create an invitation link using django rest framework? 
<http://groups.google.com/group/django-rest-framework/t/6416310b6a449fb6?utm_source=digest&utm_medium=email>
Pradyum Gupta <prady...@gmail.com>: Sep 24 01:18PM +0530

Thank you
@Naveen Kumar and @Matemática A3K
Will try both the options.

Regards
Pradyum


On Wed, Sep 23, 2020 at 12:12 PM naveen Kumar <naveenkumar...@gmail.com>
wrote:

Back to top
You received this digest because you're subscribed to updates for this group. 
You can change your settings on the group membership 
page<%20%20https:/groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/django-rest-framework/join>.
To unsubscribe from this group and stop receiving emails from it send an email 
to 
django-rest-framework+unsubscr...@googlegroups.com<mailto:django-rest-framework+unsubscr...@googlegroups.com>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/SG2PR04MB2761CEBE4ECB12528CDE0F89A7390%40SG2PR04MB2761.apcprd04.prod.outlook.com.

Reply via email to