1

In one of my views I am importing models from two apps:

from mysite.business.models import Location
from mysite.directory.models import Location

As you can see, both Models have the same name. If I want to create an instance of one of these models, how do I define which one I require?

1 Answer 1

9

Give them different names.

from mysite.business.models import Location as BusinessLocation
from mysite.directory.models import Location as DirectoryLocation
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Ignacio. I was considering this approach but hadn't found it anywhere in the Django docs. Is this the recommended way of handling the same situation when using 3rd party apps?
It's the standard way of handling import conflicts in Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.