小编Kis*_*war的帖子

Django从模型中保存以前的对象

在Django管理站点中,我有这个类.我想保存一个对象的先前版本(服务器),这是一个很多的字段来查找对象的更改.

使用普通的CharField可以正常工作,但是对于许多领域我都遇到了这个错误:

"<SourceDestinationGroup: asdas>" needs to have a value for field "id" before this many-to-many relationship can be used.
Run Code Online (Sandbox Code Playgroud)

这是我的对象类

class SourceDestinationGroup(models.Model):
    STATE_CHOICES = (
        ('C', 'in Change'),
        ('F', 'Finished')
        )
    ServerGroupName = models.CharField(max_length=256)
    Description = models.CharField(max_length=256,blank=True)
    Servers = models.ManyToManyField(Server)
    Status = models.CharField(max_length=1, choices=STATE_CHOICES, default='C')



    def __init__(self, *args, **kw):
        super(SourceDestinationGroup, self).__init__(*args, **kw)
        self._old_Servers = self.Servers

    def save(self, **kw):
       if self.Servers != self._old_Servers:
            self.Status = 'C'
            self._old_Servers = self.Servers

        super(SourceDestinationGroup, self).save(**kw)



   def __str__(self):
       return self.ServerGroupName
Run Code Online (Sandbox Code Playgroud)

python django django-models django-admin

11
推荐指数
1
解决办法
251
查看次数

angular 8:为什么组件没有加载?

所以我用angular-cli. 我在src目录中有以下结构。

. ??? app ?   ??? app-routing.module.ts ?   ??? app.component.css ?   ??? app.component.html ?   ??? app.component.spec.ts ?   ??? app.component.ts ?   ??? app.module.ts ?   ??? notifications ?   ??? notifications.component.css ?   ??? notifications.component.html ?   ??? notifications.component.spec.ts ?   ??? notifications.component.ts ??? assets ??? environments ?   ??? environment.prod.ts ?   ??? environment.ts ??? favicon.ico ??? index.html ??? main.ts ??? polyfills.ts ??? protocol.js ??? styles.css ??? test.ts

路线有以下。

RouterModule.forRoot([
        { path: '', component: AppComponent },
        { path: 'notifications', component: NotificationsComponent}
    ]) …
Run Code Online (Sandbox Code Playgroud)

angular angular-router angular8

8
推荐指数
1
解决办法
1万
查看次数

has_object_permission 未调用

我查看了关于同一主题的类似问题,我认为我遵循了为has_object_permission.

这就是我在我的设置中所拥有的。

REST_FRAMEWORK = {
    
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
        'users.permissions.CanAccessData', # this is my custom class
    ],    
    ... 
}
Run Code Online (Sandbox Code Playgroud)

这是我的权限类

class CanAccessData(permissions.BasePermission):
    message = 'You do not have permission to perform this action.'

    def has_permission(self, request, view):
        print "has_permission`"
        return True

    def has_object_permission(self, request, view, obj):
        print "has_object_permission"
        return False
Run Code Online (Sandbox Code Playgroud)

这是我的视图结构:

class CompleteList(generics.ListCreateAPIView):
    permission_classes = (CanAccessData,)
    serializer_class = SomeSerializer
    model = Some
    filter_backends = (filters.OrderingFilter, filters.SearchFilter)
    ordering_fields = (tuple of Some fields)
    search_fields = ordering_fields
    ordering = …
Run Code Online (Sandbox Code Playgroud)

django django-permissions django-rest-framework

6
推荐指数
1
解决办法
2707
查看次数

git 自动完成不会提示分支名称

我尝试了该线程中提到的所有内容,但当我双击tab命令键时git checkout,我只得到以下建议

FETCH_HEAD HEAD ORIG_HEAD

而我期待的是分支名称。

还有其他建议可以让这个工作吗?

我在ubuutu 14.04

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty
Run Code Online (Sandbox Code Playgroud)

更新

全局 gitconfig 文件

[user]
        email = abc@zxc.com
        name = Abc Zxc
[credential]
        helper = cache --timeout=3600
[filter "lfs"]
        process = git-lfs filter-process
        required = true
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
[diff]
        tool = meld
[merge]
        tool = meld
[difftool]
        prompt = false
Run Code Online (Sandbox Code Playgroud)

git版本

kishor@kishor-ThinkCentre-E73:~$ git version
git …
Run Code Online (Sandbox Code Playgroud)

git bash git-completion

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

django-admin makemessages --no-obsolete似乎不起作用

首先,我期待--no-obsolete会注释掉msgid,msgstr如果gettext被删除,对吧?

我的测试方法是:

  1. gettext("some string here")在视野中 写道
  2. 我跑了makemessages命令
  3. .po按预期编写了一个文件
  4. 然后我gettext()从视图中删除了行并保存了文件,验证了runserver工作.
  5. 我跑了makemessages --no-obsolete,它没有对.po文件进行任何更改.

.po 文件内容提取.

#. Translators: This message is a test of wrap line
#: servers/views.py:31
msgid "Do let me know if it works."
msgstr ""
Run Code Online (Sandbox Code Playgroud)

开发环境

Django = 1.11
OS = Mac/Ubuntu 14.04

settings.py

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = …
Run Code Online (Sandbox Code Playgroud)

django django-admin django-management-command makemessages

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

是否有适用于材质角度的辅助 CSS 的文档?

所以我正在使用angular-cli 8.3.5material-angular 8.2.1

我正在尝试将 HTML 居中,但没有找到有关帮助程序类的任何文档。

有谁知道如何完成我正在做的任务?

materialize angular-material angular8

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

python subprocess.Popen() 与消息队列(celery)

我读到消息队列优于subprocess.Popen(). 据说消息队列是可扩展的解决方案。我想了解这是怎么回事。

我只是想列出消息队列的好处subeprocess.Popen(),以便我可以说服我的上级使用消息队列而不是subprocess

python django celery django-celery

2
推荐指数
1
解决办法
1807
查看次数