同时使用 Django 和 GeoDjango

Use of Django and GeoDjango simultaneously

我对将 GeoDjango 与 Django 一起使用有疑问。 我的项目中有两个应用程序:BlogMap。这两个应用程序与第三个应用程序 Kernel 有关。在内核内部有一些对博客和地图有用的模型,其中之一是 TimeManager.

TimeManager 是一个“管理时间”的简单模型:

from django.db import models

class TimeManager(models.Model):
    publishing_date = models.DateTimeField(
        'Published at',
        default=timezone.now,
        )
    updating_date = models.DateTimeField(
        'Updated at',
        auto_now=True,
        )
    timestamp = models.DateTimeField(
        auto_now=False,
        auto_now_add=True,
        )

    class Meta:
        abstract = True

进入Blog有一个模型Post:

from django.db import models

from kernel.models import TimeManager

class Post(TimeManager):
    title=
    slug=
    descrtiption=
    .
    .

Into Map有一个模型MyMap:

from django.contrib.gis.db import models

from kernel.models import TimeManager

class MyMap(TimeManager):
    geom = models.PointField()
    title = 
    .
    .

现在,我的疑问是:将 TimeManager 用于几何模型而不是几何模型是否正确?我知道 GeoDjango 继承自 Django 模型,但我不知道我的方法是否正确。

这完全没有问题。 GeoDjango 已经很好的融入了 Django 项目本身,所以这里没有理由冲突。 GeoDjango 是 contrib 包的一部分。 The Django docs on the contrib package:

Django aims to follow Python’s “batteries included” philosophy. It ships with a variety of extra, optional tools that solve common Web-development problems.

This code lives in django/contrib in the Django distribution.

这意味着您可以假设 django.contrib 中包含的任何其他 Django 功能都可以与 Django 的其余部分一起使用。

只需确保记录哪些应用程序使用 GeoDjango,以及如何在系统上配置地理空间库,以防您想将应用程序变成可重用的库,这应该很好。

只要 Kernel 是某种基础应用程序,这种用例是创建具有某种日期和时间管理的对象的一种很好的 方式。