I am trying to use mongodb with django. My main poject name is 'mysite' and inside that there is an app named 'blog' and inside blog/models.py, I have written the following portion.
from django.db import models
from djangotoolbox.fields import ListField
class Post(models.Model):
title = models.CharField()
text = models.TextField()
tags = ListField()
comments = ListField()
I have installed djangotoolbox. When I run the command on python shell
from blog.models import Post
It shows the following error.
>>> from blog.models import Post
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "E:\Study\mysite\blog\models.py", line 2, in <module>
from djangotoolbox.fields import ListField
File "C:\Program Files (x86)\Python36-32\Lib\site-packages\djangotoolbox\fields.py", line 4, in <module>
from django.utils.importlib import import_module
ModuleNotFoundError: No module named 'django.utils.importlib'
>>>
Why is this error occurring? and what is its solution? Because I have seen all over the internet and could not find any.
ListField to override the formfield method:
models.py
Then, in forms.py, we define StringListField:
admin.py
This will covert the comma-separated input box contents into a Python list, and the list value that is fetched from the database int a comma-separated string which is then displayed in the input box.