我在Ubunto 15.10上运行带有JDK 8的PyCharm 5.问题是Ubuntu带有3个不同的Python版本,当我被提示在PyCharm中选择正确的解释器版本时,整个计算机就会冻结.有没有人见过类似的东西?
我的问题是一个波纹管。如果我尝试运行测试,则表明没有数据库权限,因此我必须添加该固定装置。问题是我已将该固定装置添加到我拥有的任何可能方法中,但仍然没有。因此,我假设我不知道在何处添加此标记。
它不应该是我调用这些对象的创建类的方法:test_can_get_page_details
?
如果我从将用户分配给那些属性中删除UserFactory,则测试有效。
[pytest]
DJANGO_SETTINGS_MODULE=core.settings_test
Run Code Online (Sandbox Code Playgroud)
import pytest
from bs4 import BeautifulSoup
import datetime
from django.core.urlresolvers import reverse
from interface.tests import factories
class TestPageDetail:
@pytest.fixture
def defaults(self, db):
page = factories.PageFactory()
url = page.get_absolute_url()
return {
'page': page,
'url': url
}
@pytest.mark.integration
def test_can_get_page_details(self, defaults, db, admin_client):
response = admin_client.get(defaults['url'])
assert 200 == response.status_code
Run Code Online (Sandbox Code Playgroud)
import pytest
@pytest.fixture
def initial_data(db):
from interface.management.commands.initial_data import Command as InitialData
InitialData().handle()
@pytest.fixture
def page_and_variable(db, initial_data):
from interface.tests.factories import PageFactory, VariableFactory
page …
Run Code Online (Sandbox Code Playgroud) 我将我必须的服务器迁移到 Ubuntu 16.04 并systemd
替换了upstart
. 我有三个开发环境:生产、登台和开发。只有后一个使用本地数据库,其他两个使用远程数据库。因此,为了处理部署和服务,我设法创建以下systemd
服务文件:
[Unit]
Description=Gunicorn service for Project
After=network.target
[Service]
User=projuser
WorkingDirectory=/home/projuser/sites/Project/source
ExecStartPre=/usr/bin/env DJANGO_SETTINGS_MODULE=v3.settings_staging
ExecStart=/home/projuser/sites/Project/env/bin/gunicorn --bind 127.0.0.1:8090 --workers 6 --access-logfile ../access.log --error-logfile ../error.log v3.wsgi:application
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
服务启动了,但它似乎忽略了这一行:ExecStartPre=/usr/bin/env DJANGO_SETTINGS_MODULE=v3.settings_staging
。我可以在日志中看到以下内容:
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections …
Run Code Online (Sandbox Code Playgroud) 我有这个功能来打印DIV.
每当页面加载并点击我的"打印"链接时,显示DIV没有CSS打印.
如果我关闭Chrome的打印可视化页面并再次单击"打印"链接,则DIV会应用CSS.
有什么想法吗?
function printDiv(divId) {
var printDivCSSpre =
'<link href="/static/assets/vendor/sb-admin-2-1.0.7/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">' +
'<link href="/static/assets/vendor/sb-admin-2-1.0.7/dist/css/sb-admin-2.css" rel="stylesheet">' +
'<div style="width:1000px; padding-right:20px;">';
var printDivCSSpost = '</div>';
$('body').append('<iframe id="print_frame" name="print_frame" width="0" height="0" frameborder="0" src="about:blank"></iframe>');
$("link").clone().appendTo($("#print_frame").contents().find("head"));
window.frames["print_frame"].document.body.innerHTML =
printDivCSSpre + document.getElementById(divId).innerHTML + printDivCSSpost;
window.frames["print_frame"].window.focus();
var windowInstance = window.frames["print_frame"].window;
windowInstance.print();
}
Run Code Online (Sandbox Code Playgroud)
<a id="print" href="#">
<i class="fa fa-print"></i> Print
</a>
<script>
$('#print').click(function () {
printDiv('report')
})
</script>
<div id="report" class="report">
<p># Generated Table#</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我有以下关系:
class Invoice(models.Model):
customer = models.OnetoOneField('Customer')
""" Other stuff """
class Customer(models.Model):
name = models.CharField()
""" Other stuff """
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如果我进行查询,可以说:
inv_q = Invoice.objects.filter(date=today())
如何从此查询中获取所有相关客户?
cus_q = Customer.objects.filter(id__in=inv_q.customer)
我必须为此创建一个客户经理吗?
我正在生成一个report.json
必须包含这两个信息的文件。为了不访问数据库并获取所有客户,我想从所选发票的客户那里获取信息。
鉴于以下代码:
payments = Payment.objects.filter(
customer=self.customer,
created_at__gte=kwargs['start_date'],
created_at__lte=kwargs['end_date']
).order_by('-date')
balance = payments.values('currency').annotate(Sum('amount'))
> print(balance)
> [{'amount__sum': Decimal('0.00'), 'currency': 'USD'},
{'amount__sum': Decimal('0.00'), 'currency': 'USD'},
{'amount__sum': Decimal('9000.00'), 'currency': 'SEK'},
{'amount__sum': Decimal('45000.00'), 'currency': 'EUR'},
{'amount__sum': Decimal('11385.00'), 'currency': 'SEK'}]
Run Code Online (Sandbox Code Playgroud)
该客户的付款清单:
> print(payments)
> ('-1487.50', 'USD')
('1487.50', 'USD')
('-3663.72', 'USD')
('3663.72', 'USD')
('15000.00', 'EUR')
('9000.00', 'SEK')
('30000.00', 'EUR')
('9865.00', 'SEK')
('1520.00', 'SEK')
Run Code Online (Sandbox Code Playgroud)
如果我使用聚合,我会得到总和,但对于所有货币,这不是我想要的。我必须能够拆分成货币。
{'amount__sum': Decimal('65385.00')}
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过客户分组和货币汇总来提取付款。然而,发生的情况是它不会对某些值求和,而是复制它们。有任何想法吗?
我正在尝试通过此函数提供 .json 文件。问题是每次我发出请求时,浏览器都会显示内容而不是下载文件。
我认为这可能是因为我将其.read()
用作 HttpResponse 对象构造函数的参数。但是,如果我只使用文件对象,则会出现以下异常:
TypeError: cannot serialize '_io.BufferedRandom' object
Run Code Online (Sandbox Code Playgroud)
代码
try:
invoices = models.Invoice.objects.filter(pk__in=document_ids).order_by(*ordering)
pcustomers = models.CustomerProxy.objects.all()
mixed_query = list(invoices) + list(pcustomers)
file = tempfile.NamedTemporaryFile(suffix='.json')
file.write(serializers.serialize('json', mixed_query).encode())
file.seek(0)
response = HttpResponse(file.read(), content_type='application/json')
response['Content-Disposition'] = 'attachment; filename=%s' % file.name
response['Content-Length'] = os.path.getsize(file.name)
except Exception:
raise
return response
Run Code Online (Sandbox Code Playgroud) 我需要通过一个update
操作来还原一个boolean
值。
我试过了:
Item.objects.filter(serial__in=license_ids).update(renewable=not F('renewable'))
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。我确保未将字段设置为null
。
给定以下关系:
class LicenseRequest:
license_type = models.ForeignKey(LicenseType)
created_at = models.DateField(default=now, editable=False)
class LicenseType:
name = models.CharField(max_length=100)
value = models.CharField(max_length=3, unique=True)
Run Code Online (Sandbox Code Playgroud)
我想计算为每种许可证类型创建了多少个请求。但是,由于我正在生成图形,因此对于在该特定时间段内没有任何许可证请求的许可证类型,我必须包含 0(零)。
我尝试按照此处的建议进行操作,但没有成功。我只能从具有多个许可证请求的许可证类型中获取计数。
qs = LicenseType.objects.filter(
Q(licenserequest__created_at__range=(start_date, end_date)) | Q(licenserequest__isnull=True)
).annotate(rel_count=Count('licenserequest__id'))
Run Code Online (Sandbox Code Playgroud)
我可以找到另一种方法来实现这个目标,但我想知道是否可以通过注释来做到这一点。
我正在使用django1.11.15。
/python3.4/site-packages/django/db/models/fields/subclassing.py:22: RemovedInDjango110Warning: SubfieldBase has been deprecated. Use Field.from_db_value instead.
RemovedInDjango110Warning)
Run Code Online (Sandbox Code Playgroud)
自从我升级到Django 1.9后,我开始在runserver
启动时发出此警告.问题是我不知道它来自哪里.我猜它一定是来自forms.py
.有人有线索吗?