我正在尝试在Django中创建一个独特的slug,以便我可以通过这样的URL访问帖子:http: //www.example.com/buy-a-new-bike_Boston-MA-02111_2
相关型号:
class ZipCode(models.Model):
zipcode = models.CharField(max_length=5)
city = models.CharField(max_length=64)
statecode = models.CharField(max_length=32)
class Need(models.Model):
title = models.CharField(max_length=50)
us_zip = models.CharField(max_length=5)
slug = ?????
def get_city():
zip = ZipCode.objects.get(zipcode=self.us_zip)
city = "%s, %s %s" % (zip.city, zip.statecode, zip.zipcode)
return city
Run Code Online (Sandbox Code Playgroud)
ZipCode记录示例:
样本需求记录:
有关如何创建这个独特的slug的任何提示?它的组成是:
注意:上面我想要的slug假定slug"buy-a-new-bike_Boston-MA-02111"已经存在,这就是它附加了"_2"以使其独一无二.
我尝试过django-extensions,但它似乎只需要一个字段或字段来构造独特的slug.我需要传入get_city()函数以及标题和城市之间的"_"连接符.有人解决了这个并愿意分享?
谢谢!
UPDATE
我已经在其UUIDField中使用了django-extensions,所以如果它也可用于其AutoSlugField会很好!
RSpec允许您通过执行以下操作来获取before(:each)块中当前运行的测试方法名称:
Spec::Runner.configure do |config|
config.before :each do |x|
x.method_name # returns 'should be cool'
end
end
Run Code Online (Sandbox Code Playgroud)
这是一个测试,如:
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe 'Hello world' do
it 'should be cool' do
# test code
end
end
Run Code Online (Sandbox Code Playgroud)
是否有可能在前面的块中获得整个测试名称(也称为"Hello World应该很酷")?
我已经看到像http://one-jar.sourceforge.net/和http://fjep.sourceforge.net/index.html这样的程序将你的应用程序jar和任何依赖项推送到一个可执行的jar中.
这样做的主要原因是什么?
我需要在两个应用程序之间进行高性能通信.我试过AppleEvent,但这不是一个好选择.我想使用命名管道,但我不知道如何在COCOA中使用它们.
在此先感谢您的帮助 :)
对于国际化项目,我必须使用Python验证名称(第一个,最后一个)的全局语法.但缺乏unicode类支持确实使事情变得更加困难.
有没有正则表达式/库可以做到这一点?
例子:
必须接受Björn,Anne-Charlotte,توماس,毛或מיק.-Björn,安妮 - 夏洛特,汤姆或这样的条目应该被拒绝.
有没有简单的方法呢?
谢谢.
在这里工作只是一点点好奇心.在处理危险的事情时,我开始考虑各种编译器及其相关标准库的实现.这是我思想的进展:
某些类标识符保留用于C++和C中的实现.
编译器必须执行编译阶段(预处理,编译,链接),就好像它们是按顺序执行一样.
C预处理器不知道标识符的保留状态.
因此,当且仅当以下情况时,程序可以使用保留标识符:
使用的保留标识符是所有预处理器符号.
预处理结果不包括保留标识符.
标识符不与编译器预定义的符号冲突(GNUC等人).
这有效吗?我对第3点和第4.3点不确定.此外,有没有办法测试它?
我有一个问题,Label控件非常闪烁.
下面是一些重现问题的代码.
怎么解决这个?
更新:前一种情况的解决方案(表单直接包含标签)是使form.DoubleBuffered = true.但这不是一般的解决方案.例如,对于SplitContainer中的标签,我该怎么办?这是我的真实情况.
更新的代码:
DoubleBufferedLabel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FlickerLabelTest
{
public class DoubleBufferedLabel : Label
{
public DoubleBufferedLabel()
{
DoubleBuffered = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
DoubleBufferedSplitContainer.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FlickerLabelTest
{
public class DoubleBufferedSplitContainer : SplitContainer
{
public DoubleBufferedSplitContainer()
{
DoubleBuffered = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
Form1.cs中:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text; …Run Code Online (Sandbox Code Playgroud) 我知道从原语中派生一个类是不可能的,但是,我希望我的课"看起来"像是一个没有演员的原语.在这种情况下,我的类将像十进制一样操作:
public interface IFoo
{
static explicit operator Decimal(IFoo tFoo);
}
public class Foo: IFoo
{
private Decimal m_iFooVal;
public Decimal Value
{
get { return m_iFooVal; }
set { m_iFooVal= value; }
}
static explicit operator Decimal(IFoo tFoo)
{
return (tFoo as Foo).Value;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用,因为无法在接口中定义显式运算符.我的代码处理接口,我想保持这样.是否可以将IFoo转换为十进制?欢迎任何替代方案.例:
IFoo tMyFooInterfaceReference = GetFooSomehow();
Decimal iVal = tMyFooInterfaceReference;
Run Code Online (Sandbox Code Playgroud) 你如何这样做,当你搜索"外星人与捕食者"时,你也会得到字符串"alienS vs predator"的结果与"S"
示例http://www.torrentz.com/search?q=alien+vs +捕食者
他们如何实现这一点?
这是高级搜索引擎的东西吗?
在REQ/REP套接字中,如果套接字向死(断开连接)节点发送请求,则消息不会被传递并停留在占用内存的消息队列中.如何清理这些未传递的消息(比方说,队列中的消息超过1分钟)?
谢谢!