This seems to fit the bill just fine.
 DrReadRange.objects.update(reading_width_days=read_range_in)

On Mar 16, 9:28 am, octopusgrabbus <old_road_f...@verizon.net> wrote:
> Django 1.2
> mod_wsgi
> Python 2.6.6
>
> When I create an object of a model of a table, what is the best way to
> update two columns? I can update one easily, but not two of them. I
> also noted the model, does not list the third key, at least that I can
> recognize.
>
> What am I asking is what constructs should be use -- pointer to code
> sample(s) to update two columns in one row or all rows?
>
> This code does not work the way I want it to:
>
> def save_dr_read_range(cycle_num, read_range_in, load_date,
> updating_user, max_read_range_in, errors, update_ok):
>     try:
>         read_range_obj = DrReadRange(cycle=cycle_num, \
>             reading_width_days=read_range_in, \
>             creation_date=load_date, \
>             created_by=str(updating_user), \
>             max_read_width=max_read_range_in)
>
>         read_range_obj.save()
>         del read_range_obj
>
>     except IntegrityError as e:
>         errors.append('Error: modifying read range table ' + e)
>         update_ok  = False
>
>     except:
>         e = sys.exc_info()[1]
>         errors.append('Error: ' + str(e) + ' occurred')
>         update_ok = False
>
>     return errors, update_ok
>
> tnx
> cmn
>
> Model:
>
> from django.db import models
>
> class DrReadRange(models.Model):
>     cycle = models.IntegerField(primary_key=True)
>     reading_width_days = models.IntegerField(primary_key=True)
>     creation_date = models.DateField(primary_key=False)
>     created_by = models.CharField(max_length=30)
>     max_read_width = models.IntegerField(null=True, blank=True)
>     class Meta:
>         db_table = u'dr_read_range'
>
> SQL that created the table:
> CREATE TABLE `dr_read_range` (
>   `cycle` smallint(6) NOT NULL default '0',
>   `reading_width_days` int(11) NOT NULL default '0',
>   `creation_date` date NOT NULL,
>   `created_by` char(10) NOT NULL default 'amr',
>   `max_read_width` smallint(6) default '3',
>   PRIMARY KEY  (`cycle`,`reading_width_days`,`creation_date`),
>   KEY `creation_date_ix1` (`creation_date`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='holds daily reads
> range';
> SE

-- 
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.

Reply via email to