save

Incrementing the slug by avoiding Integrity error in django models save method

送分小仙女□ 提交于 2019-12-06 09:45:18
问题 I have a model with two fields as below models.py class Publisher(models.Model): name = models.CharField(max_length=200) slug = models.SlugField(max_length=150, unique=True) def save(self, *args, **kwargs): if not self.id and not self.slug: slug = slugify(self.name) try: slug_exits = Publisher.objects.get(slug=slug) if slug_exits: self.slug = slug + '_1' except Publisher.DoesNotExist: self.slug = slug super(Publisher, self).save(*args, **kwargs) Here i am creating a slug based on the name

iPhone - different ways to store data, advantages and disadvantages

雨燕双飞 提交于 2019-12-06 08:54:55
问题 Could you explain me which are the different ways to store datas on the iPhone, and for each way of doig this, which are the advantages and disadvantages. I've read many things about UserDefaults, CoreData, XML, plist, ... and I'm a little bit lost. For now, I understand that : UserDefault is for preferences, and is not intended for anything else even if it can be done (small ammount of datas). It generates a plist file that can be easily humanly read/checked later into XCode. XML is good for

c#: reduced image quality when saving JPEG at 100% quality

痴心易碎 提交于 2019-12-06 08:51:49
问题 I'm just loading JPEG image and saving it without any manipulation with it. But image quality noticeably reducing. Here is the code: Bitmap imgOutput = new Bitmap(@"D:\image.jpg"); Graphics outputGraphics = Graphics.FromImage(imgOutput); EncoderParameters myEncoderParameters = new EncoderParameters(3); myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L); myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod,

Loading and saving variables in R with gWidgets

廉价感情. 提交于 2019-12-06 07:56:16
For the past few months I've been building a simulation in R I hope to package. It consists of two usable functions, and many internal ones which one of the two usable functions call while looping, to perform the stages of simulation. A simple conceptual example is: # Abstract representation 1st Usable function, generates object containing settings for simulation. settings <- function(){ matrix(c(1:4),nrow=2,ncol=2) } # Abstract representation of one of many internal functions, does some action in simulation. int.func <- function(x){ out <- x*2 return(out) } # Abstract representation of second

Best place to save user information for Windows XP and Vista applications

夙愿已清 提交于 2019-12-06 07:55:20
问题 I need to save a user's login information in encrypted form for this application I'm building, but I'm not sure of the best place to save the file. I don't want to save it into the program application folder as I want it per user. So what is the best folder (or way) to save it into? Edit: Using C++. 回答1: Seems like C:\Documents and Settings\%username%\Local Settings\Application Data may be the appropriate place according to Wikipedia. The article says this location is used for "User-specific

Adequetely safe method of overwriting a save file?

你。 提交于 2019-12-06 06:36:57
Using cstdio , what is the safest way of overwriting a file? 'safe' in this case meaning that there's no chance the file will become incomplete or corrupted; the file will either be the completely overwritten, or it will be the old file should something have gone awry. I imagine the best way to do this, would be to create a temporary intermediate file, then overwrite the old file once that intermediate is complete. If that actually is the best way though, there's a few other problems that'd seem possible, if albeit rare. How would I know to use this other file should the program quit while

Python <No such file or directory: 'gs'> error even with GhostScript installed on Macintosh *Issue still Persisting!*

只愿长相守 提交于 2019-12-06 06:00:36
问题 I have implemented the following save function in my program which allows the user to save as a JPEG file whatever he/she draws on the Tkinter canvas with the Turtle. How it is supposed to work is that it first captures the screen and Tkinter canvas and then creates a postscript file based on it. Then it converts that postscript file as a PIL (Python Imaging Library) readable file type, and then the PIL saves the converted file as a JPEG. My save function is shown below: def savefirst(): #

Save an imagesc output in Matlab

微笑、不失礼 提交于 2019-12-06 05:04:44
I am using imagesc to get an integral image. However, I only manage to display it and then I have to save it by hand, I can't find a way to save the image from the script with imwrite or imsave. Is it possible at all? The code: image='C:\image.jpg'; in1= imread((image)); in=rgb2gray(in1); in_in= cumsum(cumsum(double(in)), 2); figure, imagesc(in_in); Malife You can also use the print command. For instance if you are running over multiple images and want to serialize them and save them, you can do something like: % Create a new figure figure (fig_ct) % Plot your figure % save the figure to your

Tensorflow - saving and restoring from different folders

血红的双手。 提交于 2019-12-06 05:04:30
I created and saved simple nn in tensorflow: import tensorflow as tf import numpy as np x = tf.placeholder(tf.float32, [1, 1],name='input_placeholder') y = tf.placeholder(tf.float32, [1, 1],name='input_placeholder') W = tf.get_variable('W', [1, 1]) layer = tf.matmul(x, W, name='layer') loss = tf.subtract(y,layer) train_step = tf.train.AdagradOptimizer(0.1).minimize(loss, name='train_step') all_saver = tf.train.Saver() sess = tf.Session() sess.run(tf.global_variables_initializer()) x_test = np.zeros((1, 1)) y_test = np.zeros((1, 1)) some_output = sess.run([train_step],feed_dict = {x:x_test,y:y

Save Bitmap image to SD card - problem in API 1.5?

孤街醉人 提交于 2019-12-06 04:58:55
Any idea why this is not working on a HTC Hero running on Android API 1.5 ? private static void Save_to_SD (Bitmap bm, String image_name){ String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); String meteoDirectory_path = extStorageDirectory + "/Weather_Belgium"; OutputStream outStream = null; File file = new File(meteoDirectory_path, "/"+ image_name); try { outStream = new FileOutputStream(file); bm.compress(Bitmap.CompressFormat.PNG, 100, outStream); outStream.flush(); outStream.close(); Log.i("Hub", "OK, Image Saved to SD"); Log.i("Hub", "height = "+ bm