Useradd group change

pull/530/head
ibuler 8 years ago
parent e48f36397e
commit 6e46a17d98

@ -13,9 +13,17 @@ class UserAddForm(ModelForm):
'username', 'name', 'email', 'groups', 'wechat',
'phone', 'enable_2FA', 'role', 'date_expired', 'comment',
]
# widgets = {
# 'groups': forms.SelectMultiple(attrs={'class': 'chosen-select'})
# }
help_texts = {
'username': '* required',
'name': '* required',
'email': '* required',
'groups': '* required'
}
widgets = {
'groups': forms.SelectMultiple(attrs={'class': 'chosen-select', 'data-placeholder': '请选择用户组'})
}
class UserUpdateForm(ModelForm):
@ -26,6 +34,13 @@ class UserUpdateForm(ModelForm):
'phone', 'enable_2FA', 'role', 'date_expired', 'comment',
]
help_texts = {
'username': '* required',
'name': '* required',
'email': '* required',
'groups': '* required'
}
class UserGroupForm(ModelForm):
class Meta:
@ -33,3 +48,6 @@ class UserGroupForm(ModelForm):
fields = [
'name', 'comment',
]
help_texts = {
'name': '* required'
}

@ -75,7 +75,7 @@ class UserGroup(models.Model):
class User(AbstractUser):
username = models.CharField(max_length=20, unique=True, verbose_name='用户名', help_text='* required')
username = models.CharField(max_length=20, unique=True, verbose_name='用户名')
name = models.CharField(max_length=20, verbose_name='姓名', help_text='* required')
email = models.EmailField(max_length=30, unique=True, verbose_name='邮件', help_text='* required')
groups = models.ManyToManyField(UserGroup, verbose_name='用户组', help_text='* required')

@ -3,7 +3,7 @@
{% load bootstrap %}
{% block custom_head_css_js %}
<link href="{% static "css/plugins/chosen/chosen.css" %}" rel="stylesheet">
<script href="{% static "js/plugins/chosen/chosen.jquery.min.js" %}" type="text/javascript"></script>
<script src="{% static "js/plugins/chosen/chosen.jquery.min.js" %}"></script>
{% endblock %}
{% block content %}
@ -67,18 +67,18 @@
</div>
{% endblock %}
{% block custom_foot_js %}
<script type="text/javascript">
{#$(document).ready(function() {#}
{# var config = {#}
{# '.chosen-select': {},#}
{# '.chosen-select-deselect': {allow_single_deselect: true},#}
{# '.chosen-select-no-single': {disable_search_threshold: 10},#}
{# '.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},#}
{# '.chosen-select-width': {width: "95%"}#}
{# };#}
{# for (var selector in config) {#}
{# $(selector).chosen(config[selector]);#}
{# }#}
{#})#}
</script>
<script>
$(document).ready(function () {
var config = {
'.chosen-select' : {},
'.chosen-select-deselect' : {allow_single_deselect:true},
'.chosen-select-no-single' : {disable_search_threshold:10},
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
'.chosen-select-width' : {width:"95%"}
};
for (var selector in config) {
$(selector).chosen(config[selector]);
}
})
</script>
{% endblock %}

@ -24,7 +24,7 @@
<div class="">
<a href="{% url 'users:user-add' %}" class="btn btn-sm btn-primary "> 添加用户 </a>
<a id="del_btn" class="btn btn-sm btn-danger "> 删除所选 </a>
<form id="search_form" method="get" action="{% url 'users:user-list' %}" class="pull-right mail-search">
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" name="keyword" placeholder="用户名或姓名" value="{{ keyword }}">
<div class="input-group-btn">

@ -38,7 +38,6 @@
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
<span class="help-block m-b-none">用户和用户组必选一个</span>
</div>
</div>

@ -24,7 +24,7 @@
<div class="">
<a href="{% url 'users:usergroup-add' %}" class="btn btn-sm btn-primary "> 添加用户组 </a>
<a id="del_btn" class="btn btn-sm btn-danger "> 删除所选 </a>
<form id="search_form" method="get" action="{% url 'users:user-list' %}" class="pull-right mail-search">
<form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group">
<input type="text" class="form-control input-sm" name="keyword" placeholder="名称" value="{{ keyword }}">
<div class="input-group-btn">

@ -0,0 +1,33 @@
58
/root/env2.7/lib/python2.7/site-packages/django/db/models/fields/__init__.pyc in get_prep_value(self, value)
944 if value is None:
945 return None
--> 946 return int(value)
947
948 def contribute_to_class(self, cls, name, **kwargs):
TypeError: int() argument must be a string or a number, not 'QuerySet'
In [6]: group.user_set.update(users)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-94520763e8e7> in <module>()
----> 1 group.user_set.update(users)
/root/env2.7/lib/python2.7/site-packages/django/db/models/manager.pyc in manager_method(self, *args, **kwargs)
83 def create_method(name, method):
84 def manager_method(self, *args, **kwargs):
---> 85 return getattr(self.get_queryset(), name)(*args, **kwargs)
86 manager_method.__name__ = method.__name__
87 manager_method.__doc__ = method.__doc__
TypeError: update() takes exactly 1 argument (2 given)
In [7]: users
Out[7]: <QuerySet [<User: christina86>, <User: tina71>, <User: emily71>, <User: tammy66>, <User: sarah66>, <User: linda75>, <User: ev
elyn88>, <User: mildred72>, <User: sharon93>, <User: christina88>, <User: heather80>, <User: amy80>, <User: julia81>, <User: sarah89>
, <User: phillip74>, <User: kimberly74>, <User: ann73>, <User: helen63>, <User: joyce77>, <User: debra67>, '...(remaining elements tr
uncated)...']>
In [8]: group.user_set
Loading…
Cancel
Save