Django自定义保存和更新(Django custom save and update)
我有一个模型的自定义保存方法。
class Ticket(models.Model): show = models.ForeignKey(Show) seat = models.ForeignKey(Seat) ref = models.CharField(max_length=100) paid = models.BooleanField(default=False) class Meta: unique_together = ('show', 'seat') def save(self, *args, **kwargs): if self.paid: do_something()
在视图中,我想更新多个Ticket对象:
Ticket.objects.filter(ref='ref').update(paid=True)
但是,因为这不会调用自定义保存方法。 方法
do_something()
将不会被处理。 有什么方法可以解决这个问题吗?I have a custom save method for a model.
class Ticket(models.Model): show = models.ForeignKey(Show) seat = models.ForeignKey(Seat) ref = models.CharField(max_length=100) paid = models.BooleanField(default=False) class Meta: unique_together = ('show', 'seat') def save(self, *args, **kwargs): if self.paid: do_something()
In the view I would like to update multiple Ticket objects:
Ticket.objects.filter(ref='ref').update(paid=True)
But, since this won't call the custom save method. The method
do_something()
won't be processed. Is there any way to solve this problem?
原文:https://stackoverflow.com/questions/44946304
最满意答案
您需要的工具仍处于测试阶段。 您可以从http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&displaylang=en获取它们。 它们可以与您拥有的任何版本的Visual Studio一起使用(Express直到最终版。)我刚刚在博客上写了一些资源链接,以帮助您入门: http : //www.gregcons.com/KateBlog/SomeWindowsPhone7Resources.aspx 。
The tools you need are still in beta. You can get them from http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&displaylang=en . They work with whatever version of Visual Studio you have (Express right up to ultimate.) I just blogged some links to resources to help you get started: http://www.gregcons.com/KateBlog/SomeWindowsPhone7Resources.aspx.
相关问答
更多-
您需要的工具仍处于测试阶段。 您可以从http://www.microsoft.com/downloads/details.aspx?FamilyID=c8496c2a-54d9-4b11-9491-a1bfaf32f2e3&displaylang=en获取它们。 它们可以与您拥有的任何版本的Visual Studio一起使用(Express直到最终版。)我刚刚在博客上写了一些资源链接,以帮助您入门: http : //www.gregcons.com/KateBlog/SomeWindowsPhone7R ...
-
您不应该按照建议从视图模型中调用故事板。 故事是特定于视图的,您将删除代码的可测试性和可移植性。 您的问题不是非常具体,并且没有代码示例,所以它不是很容易帮助,但考虑使用触发器来启动您的故事板。 这样您就可以在视图中保留所有内容。 如果视图模型中有属性,则可以使用数据触发器在更改值时启动故事板。 也许类似于此 进口: xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:core="using:Microsoft.Xaml.In ...
-
Windows 8手机应用程序(windows 8 phone application)[2022-11-05]
是的,您需要Windows 8. IDE不会安装在较旧的操作系统上。 此外,如果您希望能够运行可以查看/调试程序的Windows Phone模拟器,则需要Windows 8 64位。 此外,您的计算机需要足够现代,处理器必须支持Hyper-V虚拟化,这是Windows Phone仿真器的另一个先决条件。 如果您没有此支持,那么您将无法在模拟器上进行调试。 您可以使用coreinfo来了解您的计算机是否符合条件。 不可以。您在Windows Vista上唯一能做的就是运行Windows 8虚拟机。确保您的虚拟 ... -
目前,英特尔XDK不支持使用Apache * Cordova插件构建Windows Phone应用程序。 没有任何适用于Windows Phone的Cordova插件允许从您的应用程序启动其他应用程序。 Currently, Intel XDK doesn't support building Windows Phone apps with Apache* Cordova plugins. There aren't any Cordova plugins for Windows Phone that all ...
-
您可以使用所需的颜色简单地替换图像中的透明度。 You can simply replace transparency in your images with the color you want.
-
无法访问当前Windows Phone SDK中的静音,振动和音量设置。 Similair问题: 如何使用C#访问Windows Phone的静音/振动模式? It is not possible to access the silent, vibrate and volume settings in the current Windows Phone SDK. Similair question: How to access silent/vibrate mode for windows phone us ...
-
Mango确实是Windows Phone 7.5更新的代号。 Windows Phone 7.5中有许多新的API和功能,它带来了一个新的SDK(版本7.1)。 针对Windows Phone 7.0 SDK的应用在7.1下工作正常,但针对Windows Phone 7.1 SDK的应用需要运行Mango更新。 Windows Phone站点列出了Windows Phone 7.5(Mango更新)中的新功能, MSDN列出了7.0 SDK和7.1 SDK之间的API更改。 Mango was indee ...
-
如何在开发Windows Phone 7应用程序时处理不同的屏幕尺寸(How to handle different screen size while developing windows phone 7 app)[2022-01-18]
正如评论中所说,WinPhone7只有一个分辨率,但要为新设备(WinPhone8)做好准备,你应该编写如下代码: using System.Windows; public void GetScreenResolution(out int w, out int h) { w = Application.Current.Host.Content.ActualWidth; h = Application.Current.Host.Content.ActualHeight; ... -
您可以通过在应用程序列表中查看应用程序来固定应用程序(向右滚动),然后单击并按住并选择出现的“固定到开始”菜单选项。 You can pin an application by viewing it in the application list (scroll to the right) and then clicking and holding and selecting the Pin To Start menu option that appears.
-
Windows Mobile和Windows Phone开发在一个盒子上?(Windows Mobile & Windows Phone development on one box?)[2022-05-17]
Trevor,这个问题已被报道为Jeffrey Walton在Microsoft Connect上已知解决方法的错误。 该修复程序总结如下: 将目录C:\Program Files\Microsoft Visual Studio 10.0\SmartDevices\Debugger\target\wce400\armv4i为armv4i_temp 在Visual Studio 2010路径中复制目录C:\Program Files\Microsoft Visual Studio 9.0\SmartDevic ...