小编Lar*_*aro的帖子

GenericForeignKey数据迁移错误:'content_object'是无效的关键字参数

我想为Comment具有GenericForeignKey关系的model()创建数据迁移.我的模型是根据django文档contenttypes制作的.

楷模:

...
class NiceMeme(models.Model):
    """
        Example model.
    """

    name = models.CharField(max_length=140)
    image = models.ImageField(upload_to=get_path_to_store_nice_meme_images)


class Comment(models.Model):
    """
        Model to add comments to any other (non abstract) model.
    """
    ...
    user = models.ForeignKey(ExtendedUser)
    content = models.CharField(max_length=140)
    content_type = models.ForeignKey(ContentType)
    object_pk = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_pk')
Run Code Online (Sandbox Code Playgroud)

数据迁移:

...
def create_comment(apps, schema_editor):
    ...
    nice_meme = NiceMeme.objects.create(name='Nice nice meme')
    Comment.objects.create(
        user=user,
        content='Gott ist tot',
        poster_username='Friedrich',
        content_object=nice_meme
    )

...
operations = [
    migrations.RunPython(create_comment)
] …
Run Code Online (Sandbox Code Playgroud)

python django generic-foreign-key django-migrations

6
推荐指数
2
解决办法
1556
查看次数

“pygmentize:找不到命令”即使我已经在系统上安装了 pygments

我尝试使用两者在Debian 9上安装pygments,但没有方法使它在命令行上运行。apt-get install python3-pygmentspip install Pygments

我怀疑我的PATH不包含安装路径。我将/usr/lib/python3/dist-packages/添加到我的PATH中,因为 pygments 包安装在那里,但当然这不是一个解决方案,因为那里没有单个 bin 或可执行文件。那里有脚本,但没有一个具有“x”权限。

那么我应该将什么目录添加到我的PATH变量中?apt-file list python3-pygments仅显示之前添加的目录(/​​usr/lib/python3/dist-packages/)。

也许问题与我的PATH无关。我不知道。但我需要完成这项工作才能使用minted Latex 包。pygments网站上有一句话让我觉得我需要安装其他东西:

如果您安装了 pygmentize 脚本,您可以从 shell 使用 Pygments。

我希望他们能写更多关于如何安装所述脚本的文章,因为我在他们的网站或互联网上找不到任何内容。据我在网上看到的,大多数人只是正常安装 pygments,然后他们就可以使用 minted,所以我对这个“脚本”持怀疑态度。

python latex pygments pygmentize

5
推荐指数
1
解决办法
6430
查看次数