3
File "C:\Python27\Lib\site-packages\file_picker\forms.py,line 5 in <module>
from django.db.models import Q,get_model
ImportError:cannot import name get_model

I am using django 1.9.7 and file_picker 0.2.2 I don't seem to have any solution to this problem

Daniel Roseman
  • 567,968
  • 59
  • 825
  • 842
Durodola Opemipo
  • 179
  • 1
  • 11

2 Answers2

8

Try using django.apps instead:

from django.apps import apps

apps.get_model('Model')

https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.get_model

jape
  • 2,761
  • 2
  • 24
  • 57
  • 1
    Only apps.models('Model') works for me @ Django 3.0.5 – NegaOverflow May 21 '20 at 11:45
  • I had to use `apps.get_model('app_name', 'Model')` – user-124812948 Nov 18 '20 at 02:25
  • This answer is using `django.apps.apps.get_model` but providing link to `django.apps.AppConfig.get_model` which is quite confusing. Another important point is that `AppConfig.get_model` needs only one argument but [`apps.get_model`](https://docs.djangoproject.com/en/3.1/ref/applications/#django.apps.apps.get_model) needs two. That being said, `apps.get_model('Model')` will not work. – haccks Mar 24 '21 at 18:34
1

Try this,

from django.apps import apps

model_obj = get_model('app_name', 'model_name')

Where "app_name" is your app name and "model_name" is your model name.

Nitheesh MN
  • 558
  • 7
  • 17