Bonjour à tous,
Alors je viens vers vous car j'ai un souci avec mes ManyToManyField dans mes formulaires, lors ce que je sélectionnes mes différentes valeurs dans ces ManyToManyField et que je valides mon formulaire, tout mes autre champs sont enregistré dans ma base de données sauf mes champs ManytoMany, pourrait-on m'expliquer pourquoi s'il vous plait ?
Ma vue :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | def Experimentform(request): form = ExpForm(request.POST or None) if request.method == 'POST': if form.is_valid(): instance = form.save(commit=False) instance.save() form = ExpForm() context = { 'form': form, 'Usform': UserForm(), 'Lcform': LCForm(), 'Siform': SixcForm(), 'kbform': KbForm(), 'Othform': OtherForm(), 'Optform': OpticsForm(), } return render(request, 'data/experiment.html', context ) |
Mon model:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Experiment(models.Model): experiment_id = models.CharField(max_length = 250, primary_key=True,db_index=True) local_contact =models.ForeignKey(Local_Contact,on_delete=models.CASCADE,db_index=True) name_proposer =models.ForeignKey(User,on_delete=models.CASCADE,db_index=True) proposal = models.CharField(max_length = 300, blank = True) folder = models.CharField(max_length = 300, blank = True) image_folder = models.CharField(max_length = 300, blank = True) begin_date = models.DateField(null=True,blank = True,db_index=True) end_date = models.DateField(null=True,blank = True) kb_path = models.ManyToManyField(Kb,blank = True) sixc_path = models.ManyToManyField(Sixc,blank = True) optics_path = models.ManyToManyField(Optics,blank = True) other_path = models.ManyToManyField(Other,blank = True) experimental_hutch = models.CharField(max_length = 250, blank = True) sample_holder = models.CharField(max_length = 250, blank = True) evaporator = models.CharField(max_length = 250, blank = True) t_range = models.CharField(max_length = 250, blank = True) gasses = models.CharField(max_length = 250, blank = True) type_of_sample = models.CharField(max_length = 250, blank = True) Beam_energy = models.CharField(max_length = 250, blank = True) def __str__(self): return self.experiment_id |
+0
-0