Giter Club home page Giter Club logo

Comments (38)

last-partizan avatar last-partizan commented on June 1, 2024 1

That's where things stop working now.

You can try to fix it - fork django-mongoengine, make it work and create pull-request.

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

Hello, take a look at examples: https://github.com/MongoEngine/django-mongoengine/blob/master/example/tumblelog/tumblelog/admin.py

Registering model works this way.

from django-mongoengine.

jaklimoff avatar jaklimoff commented on June 1, 2024

Tried to do exactly as in example, but admin returns error

NoneType' object has no attribute '_meta'

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

That's not very helpful message.
Provide full traceback or try to locate error yourself.

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

I registered the model in the admin as explained here : https://github.com/MongoEngine/django-mongoengine/blob/master/example/tumblelog/tumblelog/admin.py
But the model is not appearing on the django admin site.
There is no error or exception being raised.

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

take a look at urls
https://github.com/MongoEngine/django-mongoengine/blob/master/example/tumblelog/tumblelog/urls.py

mongo-admin uses own admin site, not default django admin.

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

That means I can't use regular admin along side mongo-admin ?
Actually I am using both mongodb and Mysql in my project, and I want to show models of both the mongodb and Mysql on the admin site under some app.
Is this possible ?

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

Try to include mongo admin at different url, something like /mongoadmin/.

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

I did as below:

from django.conf.urls import url, include
from django.contrib import admin
from django_mongoengine import mongo_admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^cas/', include('cas.urls')),
    url(r'^product_discovery/', include('product_discovery.urls')),
    url(r'^chaining/', include('smart_selects.urls')),
    url(r'^mongonaut/', include('mongonaut.urls')),
    url(r'^mongoadmin/', mongo_admin.site.urls),

]

but then the warning comes:
WARNINGS:
?: (urls.W005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLs in this namespace

I think since the AdminSite in the mongoadmin is using django admin urls , this is just repetition.
Here:
from django.contrib.admin import sites

from mongoengine.base import TopLevelDocumentMetaclass

from django_mongoengine.mongo_admin.options import DocumentAdmin
from django_mongoengine.forms.document_options import DocumentMetaWrapper
#from django_mongoengine.mongo_admin import actions

system_check_errors = []

class AdminSite(sites.AdminSite):
index_template = "mongo_admin/index.html"

def register(self, model_or_iterable, admin_class=None, **options):

    if isinstance(model_or_iterable, TopLevelDocumentMetaclass) and not admin_class:
        admin_class = DocumentAdmin

    if isinstance(model_or_iterable, TopLevelDocumentMetaclass):
        model_or_iterable._meta = DocumentMetaWrapper(model_or_iterable)
        model_or_iterable = [model_or_iterable]

    super(AdminSite, self).register(model_or_iterable, admin_class, **options)

def unregister(self, model_or_iterable):
    if isinstance(model_or_iterable, TopLevelDocumentMetaclass):
        model_or_iterable = [model_or_iterable]

    super(AdminSite, self).unregister(model_or_iterable)

site = AdminSite()

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

changed to site = AdminSite(name="mongoadmin")
try again

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

Yeah , managed to fix the error by doing some dirty hacks (there was some issue in get_app_label function)
Can't I use list_display option for mongoadmin ?
When I used it , this error came :
'StringField' object has no attribute 'remote_field'

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

ok, will try to fix it. Thanks a lot.

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

I was able to fix it for basic list, add and change view for django 1.11
Will give pull request after fixing some other things.

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

Great!

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@last-partizan @farhan0581

I am facing the same problem here. Could you please give me any light how to use admin and mongo-admin both side by side ?

@farhan0581 you mentioned,

Yeah , managed to fix the error by doing some dirty hacks (there was some issue in get_app_label function)

Have you tested it in Django 2.0.7 ? And could you share what you actually did in the site.py of mongo_admin package ?

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

@Rakin061 i'm using it like this:

from django.contrib import admin
from django_mongoengine import mongo_admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^mongo_admin/', include(mongo_admin.site.urls)),
]

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@last-partizan
Yeah... I have also done the same.. But getting an error:-

AttributeError: 'MetaDict' object has no attribute 'abstract'

Full traceback:-

"C:\Program Files\JetBrains\PyCharm 2018.1.4\bin\runnerw.exe" F:\DjangoMongoConnector\virt\Scripts\python.exe F:/DjangoMongoConnector/manage.py runserver 8000
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000179769D3E18>
Traceback (most recent call last):
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\core\management\commands\runserver.py", line 112, in inner_run
    autoreload.raise_last_exception()
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\core\management\__init__.py", line 327, in execute
    autoreload.check_errors(django.setup)()
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\apps\registry.py", line 120, in populate
    app_config.ready()
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\contrib\admin\apps.py", line 23, in ready
    self.module.autodiscover()
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "E:\Python 3.6.3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "F:\DjangoMongoConnector\blog\admin.py", line 11, in <module>
    class Album(admin.DocumentAdmin):
  File "F:\DjangoMongoConnector\virt\src\django-mongoengine\django_mongoengine\mongo_admin\decorators.py", line 25, in _model_admin_wrapper
    admin_site.register(models, admin_class=admin_class)
  File "F:\DjangoMongoConnector\virt\src\django-mongoengine\django_mongoengine\mongo_admin\sites.py", line 24, in register
    super(AdminSite, self).register(model_or_iterable, admin_class, **options)
  File "F:\DjangoMongoConnector\virt\lib\site-packages\django\contrib\admin\sites.py", line 103, in register
    if model._meta.abstract:
AttributeError: 'MetaDict' object has no attribute 'abstract'

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

Although I didn't tested on django 2 , it is expected to work, will see asap.

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

@Rakin061 probably you trying to use django.contrib.admin with mongo models. use mongo_admin.DocumentAdmin

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

I just tested with django 2.0.7, its working fine
Here are the dependencies :
Django==2.0.7
mongoengine==0.15.3
pymongo==3.7.1
pytz==2018.5
six==1.11.0
As @last-partizan mentioned , make sure you register models using mongo_admin as :

from django_mongoengine import mongo_admin as admin
from localtest.models import City
@admin.register(City)
class CityAdmin(admin.DocumentAdmin):
pass

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@farhan0581

Yes, I did everything accordingly considering the tubmlelog example as a reference. And as you said even though I register the modes as mongo_admin, I am getting some errors.

I have also checked out some other examples but the problem is all the examples are actually in Django 1.x where something might be missing out for me.

Could you please give me any idea that, do you have to make any major changes in settings.py or models while upgrading and testing in Django 2.0.7 ?

Thanks for your help and efforts !!

from django-mongoengine.

farhan0581 avatar farhan0581 commented on June 1, 2024

I just added django_mongoengine in INSTALLED_APPS and added db settings as :

MONGODB_DATABASES = {

"default": {
    "name": 'test',
    "host": '127.0.0.1',
    "password": '',
    "username": '',
},

}

Then registered my app and admin and used it under http://your_local_url/mongoadmin.

Can you share the error you are getting ?
Make sure you are using the latest version of django-mongoengine.

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@farhan0581
Thanks!! I also did the same in my settings.py . And, I think as I used MONGODB_DATABASES like you mentioned I will no longer need mongoengine 0.15.3 any more.

And, sure .. here's my error log

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@farhan0581

I'm using djanog-mongoengine == 0.3

But, still getting the same error!!

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

@Rakin061 django-mongoengine == 0.3 is old and unsupported, use git version.

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@last-partizan

Yeah ... I used the git version you provided me earlier and my problem has been solved. Many thanks!!

But a small issue still remains that.. I can't use the contrib admin and mongo_admin side by side in the my applications....

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

@Rakin061 show your models.py, admin.py and urls.py

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@last-partizan

urls.py

from django.contrib import admin
from django.urls import path,include
from django.conf.urls import url
from django_mongoengine import mongo_admin

urlpatterns = [
    #path('user_admin/', admin.site.urls),
    path('',include('blog.urls')),
    path('admin/', mongo_admin.site.urls),
    path('blog/',include('blog.urls')),
]

models.py

from django_mongoengine import Document
from django_mongoengine import fields

class Album(Document):

    artist=fields.StringField(max_length=250)
    album_title=fields.StringField(max_length=500)
    genre=fields.StringField(max_length=100)
    album_logo=fields.StringField(max_length=1000)
    def __str__(self):
        return self.album_title+ ' - '+ self.artist

class Song(Document):

    album_title = fields.StringField(max_length=500)
    file_type=fields.StringField(max_length=10)
    song_title=fields.StringField(max_length=250)

    def __str__(self):
        return self.song_title+'.'+ self.file_type

admin.py

from django_mongoengine import mongo_admin

@mongo_admin.register(Album)
class Album(mongo_admin.DocumentAdmin):
    pass

@mongo_admin.register(Song)
class Song(mongo_admin.DocumentAdmin):
    pass

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

Looks fine. I'll try to reproduce issue when i have time.

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

I just created new project with specified configuration, and it works fine.

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

Have you been able to access both mongo_admin and Django contrib admin side by side??

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

@Rakin061 yes

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

Could you please share the url patterns /urls.py??

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024
urlpatterns = [
    path('user_admin/', admin.site.urls),
    path('admin/', mongo_admin.site.urls),
]

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

I've also done the same. Don't know why I can't use both of them concurrently?

Btw, are you using Django 2.x.?

from django-mongoengine.

last-partizan avatar last-partizan commented on June 1, 2024

Yeah. I don't know.
Take a look at my project and try to figure out what you did wrong: https://files.fm/u/yscdgh3k

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@last-partizan

Many many thanks!! I was about to ask you for that kind of reference!!
I will let you know if I could fix the problem. Cheers !!

from django-mongoengine.

Rakin061 avatar Rakin061 commented on June 1, 2024

@last-partizan

Both user_admin and mongo_admin is working fine side by side!! A great many thanks for your constant support and guideline.

THING which was heading me towards the wrong directions was the naming convention of admin in the urls.
path('admin/', mongo_admin.site.urls),

It's surprising that, any url patterns other than 'admin' will not work here !! Might be admin has any special meaning from django.contrib which has been forcing to give the url pattern of admin in this case.

Cheers!!!!

from django-mongoengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.