* mercoledì 07 febbraio 2007, alle 11:27, Russell Keith-Magee wrote : > > but the data are added also when I update the Previsione ... > > searching on group archive, I think I must implement a 'save' method > > into the Previsione class ... is correct ? > > I'm not sure I understand what you're trying to do here. The save() > method on an instance doesn't affect the m2m relations. However, there > are other mechanisms, such as saving a web form, that will modify m2m > forms.
what do you mean with "saving a web form" ?? saving the form and NOT the save method on instance ?? I use : *** myform = nf.models.form_for_model(Previsione)(req.POST) if myform.is_valid(): dati = myform.save(commit=False) *** to change eventually the 'id' value for the insert/update *** if varid is not None: dati.id=varid *** > How are you updating the Previsione instances? Using a web form? > Programmatically? Some other way? I create a web form to insert/update the Previsione data ... my urls.py: urlpatterns = patterns('modulistica.savona.views', (r'^index/$', 'index'), (r'^Previsione/$', 'previsione'), (r'^Previsione/(?P<varid>\d+)/$', 'previsione'), ) when I get the 'Previsione/' URL I go to insert the data ... when I get the 'Previsione/10/' URL I go to update the data of the Previsione(pk=10). **************************** the previsione function : def previsione(req, varid=None): if req.method == 'POST': myform = nf.models.form_for_model(Previsione)(req.POST) if myform.is_valid(): dati = myform.save(commit=False) salva_rims = True list_rims = req.POST.getlist('rims') if varid is not None: dati.id=varid clean_path=re.sub('/[0-9]+/','',req.path) else: clean_path = req.path # controlla se ci sono stati cambiamenti # nel campo m2m # old_rims=list(dati.rims.all()) new_rims=Rim.objects.in_bulk(list_rims).values() old_rims.sort() new_rims.sort() if old_rims == new_rims: salva_rims = False dati.save() if salva_rims == True: dati.rims = list_rims return HttpResponseRedirect(clean_path) else: # method GET # if varid is None: myform = nf.models.form_for_model(Previsione)() else: instance = get_object_or_404(Previsione, pk=varid) myform = nf.models.form_for_instance(instance)() return render_to_response('create_form.html', \ { 'titolo': 'Archivio Previsioni', 'form': myform.as_table() }) tanks for the help ;-))) and sorry for my english !! -- #include <stdio.h> int main(void){char c[]={10,65,110,116,111,110,105,111,32,98,97,114,98,111,110, 101,32,60,104,105,110,100,101,109,105,116,64,116,105,115,99,97,108,105,110,101, 116,46,105,116,62,10,10,0};printf("%s",c);return 0;} --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---