Re: Digest for django-rest-framework@googlegroups.com - 3 updates in 2 topics

19 views
Skip to first unread message

Pradyum Gupta

unread,
Sep 24, 2020, 5:55:00 AM9/24/20
to django-res...@googlegroups.com

Thank you for your kind reply @naveenk...@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-res...@googlegroups.com" <django-res...@googlegroups.com>
Reply to: "django-res...@googlegroups.com" <django-res...@googlegroups.com>
Date: Thursday, 24 September 2020 at 3:16 PM
To: Digest recipients <django-res...@googlegroups.com>
Subject: Digest for django-res...@googlegroups.com - 3 updates in 2 topics

 

Pradyum Gupta <pradyum...@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 <naveenk...@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...@gmail.com>
wrote:
 

Pradyum Gupta <prad...@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 <naveenk...@gmail.com>
wrote:
 

You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to django-rest-fram...@googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages