Re: Creating multiple objects at once
well, you can always write the raw SQL querie... https://docs.djangoproject.com/en/1.4/topics/db/sql/ On Sunday, September 29, 2013 10:16:47 PM UTC-5, Lachlan Musicman wrote: > > Hola, > > I have a inventory system with Parts and Part types. Part Types are > Archetypes, parts are instances of Part Types with details (unit cost, > serial number, date of purchase, etc). > > A big issue is that not all Parts have serial numbers (box of 1000 > screws for instance). But when we get a large quantity of parts that I > would like to apply serial numbers to, data entry staff don't want to > enter the otherwise identical data again and again. > > Since most serialised products we are storing come with numbers that > are "in serial", I want to replace the creation process with a form > that also asks for "first serial number" and "number of parts" - > giving a nice list of easily incremented serial numbers. Then we can > create the requisite objects at the same time, and save them with just > the diff serial. > > What is the best way to do this? > > I've seen three solutions so far: > > 1. bulk_create > https://docs.djangoproject.com/en/1.4/ref/models/querysets/#bulk-create > problem: doesn't call model save method (in my case, where the slug is > populated from the id). > > 2. transaction.commit_manually > > https://docs.djangoproject.com/en/dev/topics/db/transactions/#django.db.transaction.commit_manually > > > 3. Signals > https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save > > (and now that I think about it, probably transaction.commit_manually > coupled with it). > > What does the list recommend as a method? > > Also, as I discovered in the IRC the other day, there really is a time > when CBVs aren't appropriate. Should this process be a CBV - it seems > a lot more suited to a FBV. > > Cheers > L. > > > -- > Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013: > When you used to be punk, and now you are still punk but not as punk, > are you post-punk or decaying punk or ex-punk or just not punk anymore > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f166ff7b-f449-47b1-add8-05d07759f9b5%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Creating multiple objects at once
Hola, I have a inventory system with Parts and Part types. Part Types are Archetypes, parts are instances of Part Types with details (unit cost, serial number, date of purchase, etc). A big issue is that not all Parts have serial numbers (box of 1000 screws for instance). But when we get a large quantity of parts that I would like to apply serial numbers to, data entry staff don't want to enter the otherwise identical data again and again. Since most serialised products we are storing come with numbers that are "in serial", I want to replace the creation process with a form that also asks for "first serial number" and "number of parts" - giving a nice list of easily incremented serial numbers. Then we can create the requisite objects at the same time, and save them with just the diff serial. What is the best way to do this? I've seen three solutions so far: 1. bulk_create https://docs.djangoproject.com/en/1.4/ref/models/querysets/#bulk-create problem: doesn't call model save method (in my case, where the slug is populated from the id). 2. transaction.commit_manually https://docs.djangoproject.com/en/dev/topics/db/transactions/#django.db.transaction.commit_manually 3. Signals https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_save (and now that I think about it, probably transaction.commit_manually coupled with it). What does the list recommend as a method? Also, as I discovered in the IRC the other day, there really is a time when CBVs aren't appropriate. Should this process be a CBV - it seems a lot more suited to a FBV. Cheers L. -- Maya Otos (@maya_otos) tweeted at 9:27 PM on Tue, Jul 30, 2013: When you used to be punk, and now you are still punk but not as punk, are you post-punk or decaying punk or ex-punk or just not punk anymore -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: Creating multiple objects at once
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Christian escribió: > If there a way to create multiple objects at once without calling .save > () for each object. > > Editing 200 objects with .update() is much faster than doing the same > thing with .safe() and I'm searching for a similar way to create new > objects. > What do you mean with faster? If calling 'save' is bothering you, you can create new objects using: Class.objects.create(.) But I don't see how is speed involved here. Check http://docs.djangoproject.com/en/dev/ref/models/instances/#saving-objects if you have doubts. Regards. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) iEYEAREIAAYFAkpKxwAACgkQNHr4BkRe3pJzPQCfZLRztiupOvz6evLfNJOKzlGh HzYAoIgIurWy9CLzQGbWspqntw/8N9h3 =nWvd -END PGP SIGNATURE- --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Creating multiple objects at once
If there a way to create multiple objects at once without calling .save () for each object. Editing 200 objects with .update() is much faster than doing the same thing with .safe() and I'm searching for a similar way to create new objects. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Creating multiple objects at once
Hi all, I´m currently writing an app to track expenses (using Django). For this I´ve a simple datamodel which basically consists of two model classes: Register and Entry. The idea is that you can book expenses in various Registers, one Entry representing a particular Expense. Now my issue is the following. I´d like to provide for a page where you can bulk-create say 5 expense Entries at onces. I.e. a form with 5 rows, each row being a complete input line for a single expense Entry, with a select box for selecting the Register the new entry should belong to and fields for the amount, currency etc. [Side note: This seems similar to inline edit of related objects (as done in part 2of the tutorial, Adding related objects), however is a bit different since in my case the object those Entries will be related to already exists and the entries themselves do not (where as in the examples both the poll and the choices are created at the same time).] Now, I´m familiar with FormEncode and that let me define a form like (simplified pseudocode): ... ... ... ... Decoding the POSTed data using the provided decode function returns a list of dicts (each dict representing a to-be-created Entry). I.e. [{"register_id": r111, "amount":a111}, {"register_id": r222, "amount":a222}, ..., ..., ...]. On receiving the POST data it is as simple as having the data decoded (and validated at the same time) by FormEncode, cycle through the returned list and create each entry using the dict´s contents. Can I do something similar with the Manipulator framework (or other part of Django)? And if so, how? Oh - and another (slightly related) question: how do I do something similar in effect to "for n in range(0, 4)" in a template? Currently I (ab)use an array with length 4 for this (just iterating over it and only using the loop counter), but there is probably a nicer solution. Thanks in advance, Rgds, Jeroen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---