在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) 所以我用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) 我查看了关于同一主题的类似问题,我认为我遵循了为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) 我尝试了该线程中提到的所有内容,但当我双击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) 首先,我期待--no-obsolete会注释掉msgid,msgstr如果gettext被删除,对吧?
我的测试方法是:
gettext("some string here")在视野中 写道makemessages命令 .po按预期编写了一个文件 gettext()从视图中删除了行并保存了文件,验证了runserver工作. 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) 所以我正在使用angular-cli 8.3.5和material-angular 8.2.1。
我正在尝试将 HTML 居中,但没有找到有关帮助程序类的任何文档。
有谁知道如何完成我正在做的任务?
我读到消息队列优于subprocess.Popen(). 据说消息队列是可扩展的解决方案。我想了解这是怎么回事。
我只是想列出消息队列的好处subeprocess.Popen(),以便我可以说服我的上级使用消息队列而不是subprocess
django ×4
angular8 ×2
django-admin ×2
python ×2
angular ×1
bash ×1
celery ×1
git ×1
makemessages ×1
materialize ×1