Note that there are some explanatory texts on larger screens.

plurals
  1. POUPDATE in raw sql does not hit all records although they meet the criteria
    primarykey
    data
    text
    <p>I am trying to update several records when I hit the save button in the admin with a raw sql which is located in models.py (def save(self, *args, **kwargs)</p> <p>The raw sql is like this as a prototype</p> <pre><code>cursor=connection.cursor() cursor.execute("UPDATE sales_ordered_item SET oi_delivery = %s WHERE oi_order_id = %s", ['2011-05-29', '1105212105']) </code></pre> <p>Unfortunately it does not update all records which meet the criteria. Only one and sometimes more but never all.</p> <p>With the SQLite Manager and the following SQL everything works great and all the records get updated:</p> <pre><code>UPDATE sales_ordered_item SET oi_delivery = '2011-05-29' WHERE oi_order_id = '1105212105' </code></pre> <p>I was thinking of using a manager to update the table but I have no idea how this would work when not using static data like '2011-05-29'. Anyways, it would be great to understand in the first place how to hit all records with the raw sql. Any recommendations how to solve the problems in a different way are also highly appreciated</p> <p>Here ist the code which I stripped a little to keep it short</p> <pre><code># Orders of the customers class Order(models.Model): """ Defines the order data incl. payment, shipping and delivery """ # Main Data o_customer = models.ForeignKey(Customer, related_name='customer', verbose_name=_u'Customer'), help_text=_(u'Please select the related Customer')) o_id = models.CharField(_(u'Order ID'), max_length=10, primary_key=True, help_text=_(u'ID has the format YYMMDDHHMM')) o_date = models.DateField(_(u'created')) and more... # Order Item class Ordered_item(models.Model): """ Defines the ordered item to which order it belongs, pricing is decoupled from the catalogue to be free of any changes in the pricing. Pricing and description is copied from the item catalogue as a proposal and can be altered """ oi_order = models.ForeignKey(Order, related_name='Order', verbose_name=_(u'Order ID')) oi_pos = models.CharField(_('Position'), max_length=2, default='01') oi_quantity = models.PositiveIntegerField(_('Quantity'), default=1) # Date of the delivery to determine the status of the item: ordered or already delivered oi_delivery = models.DateField(_(u'Delivery'), null=True, blank=True) and more ... def save(self, *args, **kwargs): # does not hit all records, use static values for test purposes cursor=connection.cursor() cursor.execute("UPDATE sales_ordered_item SET oi_delivery = %s WHERE oi_order_id = %s", ['2011-05-29', '1105212105']) super(Ordered_item, self).save(*args, **kwargs) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload