小编Enn*_*ael的帖子

为什么我的排除字段仍然出现在这个Django表单中?

我正在使用exclude我的表单的Meta类来从我的表单中排除我想要以编程方式填写的字段,但它仍然在表单中显示.

以下是代码的一些摘录:

# Model
class Info(models.Model):
    completed_by = models.ForeignKey(User, related_name='+')

# Form
class InfoForm(forms.ModelForm):
    class Meta:
        model = Info
        exclude = ('created_by',)  #ETA: added comma to make this a tuple
        widgets = {
            'some_other_field': forms.HiddenInput(),
            'some_other_field2': forms.DateInput(attrs={'readonly': True}),
        }

# View
form = InfoForm(initial={'some_other_field': value}, 
                          prefix='info', instance=info)
return direct_to_template(request, 'myapp/info.html', locals())

# Template
<form class='uniForm' method='POST'>
{% csrf_token %}
<fieldset class='inlineLabels'>{{ form|as_uni_form }}</fieldset>
<input type='submit' name='action' value='Save' />
</form>
Run Code Online (Sandbox Code Playgroud)

这看起来应该很简单,我知道我之前已经成功完成了.我删除/重新创建了我的数据库并清除了我的浏览器缓存,只是为了确保这不是一个因素.我也试过把它变成一个HiddenInput字段,就像some_other_field(也是一个ForeignKey字段),但它仍然出现在表单上.

这里有什么东西我不见了吗?uni_form会以某种方式覆盖设置吗?如果没有,任何关于我在调试中可能会寻找什么的建议,看看这是怎么回事?

(使用Django …

django django-forms

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

如何以编程方式设置ASP.NET ReportViewer控件的数据源?

如何以编程方式设置ASP.NET ReportViewer控件的数据源?

我有一个VS 2008 ReportViewer控件,想要在几个不同的报告之间切换.

我可以通过设置报告源并刷新控件来切换报告,但我看不到在哪里设置数据源.

每个报告都有自己的数据源,如果我在构建控件时最初配置它们就可以了,但我需要在它们之间切换.

asp.net reportviewer visual-studio-2008

5
推荐指数
1
解决办法
9988
查看次数

如何使用FILETIME/SYSTEMTIME或boost在C++中使用Win32设置文件的上次访问时间?

我有一些代码根据与上次访问日期的time_t比较删除一些文件,并且正在寻找如何编写SetLastAccessTime方法以在我的单元测试中使用.

这是我的获取:

bool GetLastAccessTime(const std::string &filename, time_t& lastAccessTime)
{
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;

    hFind = FindFirstFile(filename.c_str(), &FindFileData);

    if (hFind == INVALID_HANDLE_VALUE) 
        return false;

    FILETIME fTime = FindFileData.ftLastAccessTime;
    FindClose(hFind);

    SYSTEMTIME sTime;
    FileTimeToSystemTime(&fTime, &sTime);

    struct tm tmTime;
    tmTime.tm_hour = sTime.wHour;
    tmTime.tm_min = sTime.wMinute;
    tmTime.tm_mday = sTime.wDay;
    tmTime.tm_mon = sTime.wMonth;
    tmTime.tm_sec = sTime.wSecond;
    tmTime.tm_year = sTime.wYear - 1900;

    time_t t = mktime(&tmTime);

    lastAccessTime = t;
    return true;
}    
Run Code Online (Sandbox Code Playgroud)

我猜我是以某种方式做反向的?我甚至不确定我想要在哪里结束.

我宁愿做这样的事情:

boost::filesystem::path p(filename)
std::time_t t = boost::filesystem::last_access_time(p);
Run Code Online (Sandbox Code Playgroud)

但这似乎并不存在,从我能够找到的(虽然有一个last_write_time).如果还有另一种我忽略的boost :: filesystem技术,我当然对此持开放态度.

系统:Win32(XP),Boost库:1.44 v2,Dev env:Visual Studio …

c++ winapi boost

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