djangosnippets.org: Latest snippets tagged with 'pre_save'https://djangosnippets.org/tags/pre_save/2016-12-29T10:30:09.721190-06:00Resize or Modify an image before saving
2016-12-29T10:30:09.721190-06:00asurahttps://djangosnippets.org/snippets/10597/<p>Small snippet that will resize all images before they uploaded to the server. </p>
Freely redistributablepre_save hook for checking state changes to models
2011-11-03T08:16:23.959136-05:00FarmKinghttps://djangosnippets.org/snippets/2590/<p>Trying to build a state-machine that stores state in the model or in settings.py rather then in the database, I wrote this small generic pre_save hook that lets me leave all the data in the Model.</p>
Freely redistributableRun model validation before saving a model instance
2011-01-12T01:11:48.105528-06:00buriyhttps://djangosnippets.org/snippets/2319/<p>How to validate your model at save using the pre_save signal.
</p>
<p>from http://groups.google.com/group/django-developers/browse_thread/thread/eb2f760e4c8d7911/482d8fd36fba4596?hl=en&lnk=gst&q=problem+with+Model.objects.create#482d8fd36fba4596
</p>
Freely redistributable"Autoconnect" model decorator, easy pre_save and post_save signal connection
2010-07-24T09:01:54.601871-05:00bendavis78https://djangosnippets.org/snippets/2124/<p>This method allows you to define pre_save and post_save signal connections for your decorators in a little more clean way. Instead of calling <code>pre_save.connect(some_func, sender=MyModel)</code>, or perhaps <code>pre_save.connect(MyModel.some_static_func, sender=MyModel)</code>, you can simply define the pre_save method right on your model. The @autoconnect decorator will look for pre_save and …</p>
Freely redistributableSelfForeignKey to prevent hierarchical loops
2010-02-01T15:56:29.888726-06:00jamesgpearcehttps://djangosnippets.org/snippets/1906/<p>When you have a model containing a field that is a foreign key back to the same model, you could find yourself with a hierarchy with an infinite loop:</p>
<h1>Data modelling Back to the Future</h1>
<blockquote>
<p>grandfather > father > son > father > ...</p>
</blockquote>
<p>Using this field instead of the …</p>
Freely redistributablePreSaveMiddleware
2007-11-20T12:47:13.307587-06:00pterkhttps://djangosnippets.org/snippets/476/<p>With this middleware in place (add it to the MIDDLEWARE_CLASSES in your settings) you can pass a request to the model via a pre_save method on the model.</p>
<p>I'm not sure if it is an improvement over the [threadlocals method] (http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser) but it may be an alternative that can be …</p>
Freely redistributable