Django admin 和 MongoDB,可能吗?

2022-01-25 00:00:00 python django mongodb django-admin

问题描述

我正在构建一个简单的短 URL 服务,供我们公司使用.我想使用 mongodb 来存储数据,但我需要一些简单的接口来添加/编辑短 url 到长 url 映射.

I'm building a simple short URL service, ala bitly, for our company use. And I would like to use mongodb to store the data, but I will need some kind of simple interface to add/edit short url to long url mappings.

mongo 文档将非常简单,如下所示:

The mongo documents will be very simple, something like this:

{
  shortUrlSlug: 'pbbs',
  fullUrl: 'http://example.com/peanut/butter/and/bacon/sandwiches/'
}

是否有任何东西可以向 mongodb 公开一个简单的CRUD"管理界面,可以与 django 集成,您可以在其中指定模型?
基本类似于 django admin,但不需要 SQL 数据库.

Is there anything out there that exposes a simple "CRUD" admin interface to mongodb, that can be integrated with django, where you can specify the model?
Basically like django admin, but without requiring a SQL database.

谢谢!


解决方案

我已经确认 django-nonrel 项目确实支持管理界面.我确实遇到了一个问题,默认 SITE_ID 被选为数字,这在 MongoDB 中不允许作为主键.我通过设置解决了这个问题:

I have confirmed that django-nonrel project does support the admin interface. I did have a problem where the default SITE_ID was picked up as a number, which is not allowed as a primary key in MongoDB. I resolved this by setting:

SITE_ID = '4d421623b0207acdc500001d'

SITE_ID = '4d421623b0207acdc500001d'

在我的 settings.py 中

in my settings.py

我通过shell打印集合中第一个站点值的id得到了数字.

I got the number by printing the id of the first site value in the collection through the shell.

我没有对此进行广泛测试,但确实为 Poll 对象注册了一个管理员并看到它工作.

I have not tested this extensively, but did register an admin for a Poll object and see it work.

相关文章