小编Ara*_*ran的帖子

时区"东部标准时间"未被识别

我一直收到这个错误:

时区"东部标准时间"未被识别

这是代码:

def get_context_data(self, **kwargs):
    # Call the base implementation first to get a context
    context = super(IndexView, self).get_context_data(**kwargs)
    """Return the last five published posts."""
    context['latest_post_list'] = Post.objects.order_by('-pub_date')[:5]
    context['archives'] = Post.objects.datetimes('pub_date', 'month', order='DESC')     
    return context;
Run Code Online (Sandbox Code Playgroud)

在我的模板中:

{% for archive in archives %}
    <li><a href="#">{{ archive.month }} {{ archive.year }}</a></li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

在我的设置中:

TIME_ZONE = 'America/Montreal'
Run Code Online (Sandbox Code Playgroud)

我想做的是获得某种存档系统.在哪里可以获得不同的月份和年份,有任何帖子.

Environment:


Request Method: GET
Request URL: http://localhost:8000/blog/

Django Version: 1.6.1
Python Version: 3.3.3
Installed Applications:
('django_admin_bootstrapped.bootstrap3',
 'django_admin_bootstrapped',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages', …
Run Code Online (Sandbox Code Playgroud)

python django timezone views

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

使用换行符分解字符串

我试图使用explode函数将字符串分解为数组.

我希望它使用字符串中找到的换行符来打破字符串.

我查了一下,我尝试了所有的方法,但我无法让它工作.

这是我到目前为止:

$r = explode("\r\n" , $roster[0]);
Run Code Online (Sandbox Code Playgroud)

但是当我var_dump变量时,我得到以下内容:

array (size=1)
  0 => string '\r\n                         ( G  A  Sh Hi Ga Ta PIM, +\/-  Icetime Rating)\r\nR Danny Kristo            1  0  2  0  0  0    0    1    7.00    7\r\nR Brian Gionta            1  1  5  1  1  0    0    0   19.20    8\r\nR Steve Quailer...
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

php arrays variables explode

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

Django One to One - 不想删除相关模型

所以这就是问题所在.我有2个型号:

裁判级别和裁判

这两个是:

class RefereeLevel(models.Model):
    level = models.PositiveSmallIntegerField(blank=False,default=1,verbose_name=_("level"),unique=True)
    salary = models.DecimalField(blank=False,default=0.00,decimal_places=2,max_digits=4,verbose_name=_("salary"))

    def __unicode__(self):  # Python 2.7: def __unicode__(self):
        return self.level
Run Code Online (Sandbox Code Playgroud)

第二节课:

 class Referee(models.Model):
    member = models.OneToOneField(Member,related_name='member',blank=False)
    information = models.ForeignKey(RefereeLevel,related_name='information',blank=False,null=True,default=1)
Run Code Online (Sandbox Code Playgroud)

现在发生的是,如果我删除了RefereeLevel,那么该级别的裁判将被删除.但我不希望这样,我希望将裁判的信息设置为无.

那可能吗?

谢谢,阿拉

django one-to-one relationships

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

Django - 用基数为10的int()的Formset无效文字:''

我的表单中有一个内联字段,我试图通过save_formset()函数访问它

这是我的代码:

def save_formset(self, request, form, formset, change):
    periods = formset.save(commit=False)
    match = periods[0].match
    match_utils = MatchUtils()
    teamstat_utils = TeamStatUtils()
    is_update = match.reported
    match_type = match.tournament.type

    # Find positions
    first_place = match_utils.findPositions(periods,match.blue_team,match.grey_team,match.black_team,1)
    second_place = match_utils.findPositions(periods,match.blue_team,match.grey_team,match.black_team,2)
    third_place = match_utils.findPositions(periods,match.blue_team,match.grey_team,match.black_team,3)

    # Update Match
    match.first_place = first_place
    match.second_place = second_place
    match.third_place = third_place
    match.blue_periods_won = match_utils.findTeamPeriodsWon(periods,'blue_team')
    match.grey_periods_won = match_utils.findTeamPeriodsWon(periods,'grey_team')
    match.black_periods_won = match_utils.findTeamPeriodsWon(periods,'black_team')
    match.reported = True

    # Update team stats
    teamstat_utils.updateTeamStats(match.blue_team,match_utils.findPositionForTeam(match.blue_team,first_place,second_place,third_place),
        match.blue_periods_won,match.grey_periods_won+match.black_periods_won,is_update,match_type) #Blueteam
    teamstat_utils.updateTeamStats(match.grey_team,match_utils.findPositionForTeam(match.grey_team,first_place,second_place,third_place),
        match.grey_periods_won,match.blue_periods_won+match.black_periods_won,is_update,match_type) #Greyteam
    teamstat_utils.updateTeamStats(match.black_team,match_utils.findPositionForTeam(match.black_team,first_place,second_place,third_place),
        match.black_periods_won,match.blue_periods_won+match.grey_periods_won,is_update,match_type) #Blackteam

    pdb.set_trace()
    match.save()
    formset.save()
Run Code Online (Sandbox Code Playgroud)

但我一直得到:基数为10的int()的无效文字:''

我不知道为什么,我尝试了formset.is_valid()并返回True …

django admin save formset

0
推荐指数
1
解决办法
3084
查看次数