小编byr*_*rdr的帖子

Git从命令行注销用户

是否有退出git的命令?我正在将计算机转给其他人,并且不希望将git附加到终端中的帐户.

git

79
推荐指数
7
解决办法
16万
查看次数

Django抽象用户错误

我正在使用以下代码扩展基于文档的User类:

from django.contrib.auth.models import AbstractUser

class MyUser(AbstractUser):
  some_extra_data = models.CharField(max_length=100, blank=True)
Run Code Online (Sandbox Code Playgroud)

但是,我将返回以下错误

Reverse accessor for 'User.groups' clashes with reverse accessor for 'MyUser.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'MyUser.groups'.
Run Code Online (Sandbox Code Playgroud)

我理解通过向FK添加related_name来解决此类冲突.在这种情况下我该如何解决?

django django-users

27
推荐指数
2
解决办法
2万
查看次数

JavaScript展平对象数组的数组

我有一个包含几个数组的数组,每个数组包含几个对象,类似于此.

[[object1, object2],[object1],[object1,object2,object3]]
Run Code Online (Sandbox Code Playgroud)

这是记录到控制台的对象的屏幕截图.

什么是最好的方法来展平它,所以它只是一个对象数组?

我试过这个没有运气:

console.log(searchData);  
  var m = [].concat.apply([],searchData);    
console.log(m);
Run Code Online (Sandbox Code Playgroud)

searchData记录上面的截图,但是m登出[]

这是searchData的实际内容:

[[{"_id":"55064111d06b96d974937a6f","title":"Generic Title","shortname":"generic-title","contents":"<p>The Healing Center offers practical, social, and spiritual support to individuals and families. Services include, but are not limited to: food and clothing, job skills training and job search assistance, auto repair (Saturdays only), mentoring, financial counseling, tutoring, prayer, life skills training, and helpful information about local community services.</p><p>Stay in touch with us:</p>","__v":0},{"_id":"5508e1405c621d4aad2d2969","title":"test english","shortname":"test-page","contents":"<h2>English Test</h2>","__v":0}],[{"_id":"550b336f33a326aaee84f883","shortname":"ok-url","title":"now english","contents":"<p>okokko</p>","category":"Transportation","__v":0}]]
Run Code Online (Sandbox Code Playgroud)

javascript arrays loops flatten

24
推荐指数
5
解决办法
3万
查看次数

webpack如何处理导入同一模块的多个文件React

我有一个React应用程序,它有许多组件导入相同的模块.webpack是否为每个请求它的文件导入一次模块,导致重复的代码(在这种情况下,每个模块只导入两个组件两次)?我正在考虑重新编写组件,以便子组件不需要React模块,但也许我正在解决一个不存在的问题.如果它导致重复的代码,我想避免许多相同的反应模块的导入.

组件1

import React from "react";
import { Link } from "react-router";
import ReactLogo from "elements/ReactLogo";

export default class MainMenu extends React.Component {
    render() {
        return <div>
            <ReactLogo type="svg" /> <ReactLogo type="png" /> <ReactLogo type="jpg" />
            <h2>MainMenu:</h2>
            <ul>
                <li>The <Link to="home">home</Link> page.</li>
                <li>Do something on the <Link to="todo">todo page</Link>.</li>
                <li>Switch to <Link to="some-page">some page</Link>.</li>
                <li>Open the chat demo: <Link to="chat" params={{room: "home"}}>Chat</Link>.</li>
                <li>Open the page that shows <Link to="readme">README.md</Link>.</li>
            </ul>
        </div>;
    }
}
Run Code Online (Sandbox Code Playgroud)

组件2导入相同的3个模块.

import React from "react";
import { …
Run Code Online (Sandbox Code Playgroud)

reactjs webpack

20
推荐指数
1
解决办法
7923
查看次数

在ng-model中使用$ index的Angular

我有以下循环,其中我试图每次通过循环基于数组索引递增几个字段.

<div class="individualwrapper" ng-repeat="n in [] | range:4">
  <div class="iconimage"></div>
  <div class="icontext">
    <p>Imagine that you are in a health care facility.</p> 
    <p>Exactly what do you think this symbol means?</p>
    <textarea type="text" name="interpretation_1" ng-model="interpretation_1" ng-required="true"></textarea>
    <p>What action you would take in response to this symbol?</p>
    <textarea type="text" name="action_1" ng-model="action_1" ng-required="true"></textarea>  
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想做类似的事情"

ng-model="interpretation_{{$index + 1}}"
Run Code Online (Sandbox Code Playgroud)

Angular虽然没有渲染这个值?在mg模型领域中添加这种逻辑的最佳方法是什么?

html javascript angularjs angularjs-ng-model

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

Angular orderBy对象可能吗?

我有一个表示日历日期的JSON对象.这些是通过CMS添加的,我希望能够根据日期过滤它们.我的架构设置使得这比我想象的更难.是否可以在此JSON对象中订购日期值或是否有过滤器解决方法?

这是我的JSON对象:

{
"_id" : ObjectId("53f252537d343a9ad862866c"),
"year" : {
    "December" : [],
    "November" : [],
    "October" : [],
    "September" : [],
    "August" : [],
    "July" : [ 
        {
            "day" : "21",
            "title" : "Event Title",
            "summary" : "Event Summary",
            "description" : "oEvent Description",
            "_id" : ObjectId("53f252537d343a9ad862866d")
        }
    ],
    "June" : [],
    "May" : [],
    "April" : [],
    "March" : [],
    "February" : [],
    "January" : []
},
"__v" : 0
}
Run Code Online (Sandbox Code Playgroud)

这是我的视图,它已经使用自定义过滤器按月过滤.orderBy没有运行,但我把它留作占位符来显示我想要设置功能的位置.

<div class="calDynamic" data-ng-repeat="n in [] | range:100">
<div …
Run Code Online (Sandbox Code Playgroud)

json angularjs angularjs-orderby angular-filters

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

Django'function'对象没有属性'get'

我遇到了这个错误:

'function' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)

这看起来像点击劫持一样

这是完整的追溯

Request Method: GET
Request URL: http://localhost:8000/weblog/categories/weekly/

Django Version: 1.7
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'search',
 'coltrane',
 'tagging',
 'markdown')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  204.                 response = middleware_method(request, response)
File "/Library/Python/2.7/site-packages/django/middleware/clickjacking.py" in process_response
  31.         if response.get('X-Frame-Options', None) is not None:

Exception Type: AttributeError at /weblog/categories/weekly/
Exception Value: 'function' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)

我的观点和网址:

url(r'^(?P<slug>[-\w]+)/$', …
Run Code Online (Sandbox Code Playgroud)

django

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

Django跨越关系

我已阅读文档,但仍然出现错误.我有用户为目录对象下订单.我想创建一个查询,该查询返回具有包含特定目录项的订单的所有用户.

这是我的模特:

class Catalog(models.Model):
  name = models.CharField(max_length=100)
  price = models.IntegerField()

  def __unicode__(self):
      return self.name

class Annual(models.Model):
  catalog = models.OneToOneField(Catalog, blank=True, null=True, related_name='annual_products')
  year_id = models.IntegerField(max_length=4)
  start_date = models.CharField(max_length=10)
  end_date = models.CharField(max_length=10)
  date = models.DateTimeField(auto_now_add=True, blank=True)
  def __unicode__(self):
      return unicode(self.year_id)

class Order(models.Model):
  user = models.ForeignKey(User, related_name='who_ordered')
  select = models.ManyToManyField(Catalog, related_name='annuals_ordered', blank=True, null=True)

  def __unicode__(self):
      return unicode(self.user)
Run Code Online (Sandbox Code Playgroud)

这是我一直在尝试的查询:

 Catalog.objects.filter(order__select__annual='2014')
Run Code Online (Sandbox Code Playgroud)

django django-orm

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

Angular $ q返回承诺多个$ http调用

我正在进行$ http调用,它遍历多个api中的每一个并返回一个对象中的所有数据.我通常已经准备好在$ http调用时解决.与此类似:

function getAllData(api) {
    return $http({
        method: 'GET',
        url: '/api/' + api
    })
    .then(sendResponseData)
    .catch (sendGetVolunteerError);
}
Run Code Online (Sandbox Code Playgroud)

当前函数我遍历每个api并将api中的每个对象推送到一个数组中,然后将其推送到整个数组中.我有这个功能,返回一个多维数组,需要被展平.

我想在承诺中归还这个,但我要回来了undefined.这是我到目前为止的情况?有没有更好的方法来解决这个问题?

DataService的:

function getSearchData() {
    return {
        loadDataFromUrls: function () {
            var apiList = ["abo", "ser", "vol", "con", "giv", "blo", "par"];
            var deferred = $q.defer();
            var log = [];
            angular.forEach(apiList, function (item, key) {
                var logNew = [];
                $http({
                    method: 'GET',
                    url: '/api/' + item
                }).then(function (response) {
                    angular.forEach(response.data, function (item, key) {
                        this.push(item);
                    }, logNew);
                    return logNew; …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-promise

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

Cassandra有效的列名

我正在创建一个可以在mongo或cassandra上运行的api,因此我使用'_id'作为列名.

根据文档,这应该是一个有效的名称:

使用CQL创建的Keyspace,列和表名称只能包含字母数字和下划线字符.用户定义的数据类型名称和字段名称,用户定义的函数名称以及使用CQL创建的用户定义的聚合名称只能包含字母数字和下划线字符.如果使用除字母数字字符或下划线之外的任何内容输入这些对象的名称,Cassandra将发出无效的语法消息并且无法创建对象.

但是,当我运行此语句时:

CREATE TABLE users(_id: bigint, entires: map<timestamp, text>, PRIMARY KEY(_id));
Run Code Online (Sandbox Code Playgroud)

我返回以下错误:

Invalid syntax at line 1, char 20
Run Code Online (Sandbox Code Playgroud)

是否可以在列名称中使用下划线?

cql cassandra

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