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
  • 588,541
  • 66
  • 880
  • 895
Durodola Opemipo
  • 319
  • 2
  • 12

2 Answers2

9

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,861
  • 2
  • 26
  • 58
  • 1
    Only apps.models('Model') works for me @ Django 3.0.5 – NegaOverflow May 21 '20 at 11:45
  • 1
    I had to use `apps.get_model('app_name', 'Model')` – sebtheiler Nov 18 '20 at 02:25
  • 1
    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
2

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
  • 608
  • 8
  • 18