Django model with manytomany field, not getting saved. Is data population designed properly? -


i think i'm not populating data, model has manytomany field. wanted create model days of week, people can select days want receive mail notifications. resulting generated html, looks correct. i.e. can select checkboxes days, when click submit bottom, other fields saved in database, not days of week selection. i'm sure i'm making simple mistake, regarding how data model. can't see it. should following work? here's model days of week:

days_of_week = ( ('1', 'monday'), ('2', 'tuesday'), ('3', 'wednesday'), ('4', 'thursday'), ('5', 'friday'), ('6', 'saturday'), ('7', 'sunday'), )  class days(models.model):     days = models.charfield(max_length=1, choices=days_of_week) 

the part of mail notification model references days:

class preferences(models.model):     user = models.foreignkey(user)     mail_days = models.manytomanyfield(days) 

the part of form days selected, here:

days_of_week = (     ('1', 'monday'),     ('2', 'tuesday'),     ('3', 'wednesday'),     ('4', 'thursday'),     ('5', 'friday'),     ('6', 'saturday'),     ('7', 'sunday'),     )  mail_days = forms.multiplechoicefield(required=false,             widget=checkboxselectmultiple, choices=days_of_week) 

the form displays correctly, i.e. checkboxes days of week appear. when select boxes, , hit submit, looks ok. if select form again , checkboxes empty. other fields of form changed, saved properly.

i think perhaps see problem. here's sql database table, gets created days model. it's empty. it's not populated anything. shouldn't be?

create table `myapp_days` (     `id` int(11) not null auto_increment,     `days` varchar(1) not null,     primary key (`id`) ) engine=myisam default charset=latin1;  lock tables `todo_days` write; unlock tables; 

the selected days getting saved table called myapp_preferences_my_days:

create table `myapp_preferences_mail_days` (   `id` int(11) not null auto_increment,   `preferences_id` int(11) not null,   `days_id` int(11) not null,   primary key (`id`),   unique key `preferences_id` (`preferences_id`,`days_id`),   key `myapp_preferences_mail_days_2d9474d5` (`preferences_id`),   key `myapp_preferences_mail_days_96c2dc77` (`days_id`)   ) engine=myisam auto_increment=16 default charset=latin1;  lock tables `myapp_preferences_mail_days` write; insert `myapp_preferences_mail_days` values (15,1,6),(14,1,4),(13,1,5); unlock tables; 

any insights problem? many thanks.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -