Murilo, try to debug your "task" variable - must be an int. Also next time please provide full traceback of your error.
On 23 April 2012 17:42, akaariai <akaar...@gmail.com> wrote: > On Apr 23, 4:26 pm, Murilo Vicentini <murilofvicent...@gmail.com> > wrote: > > Hey guys, > > I'm having a bit of a problem using the get_or_create with a > > ManyToManyField in my model. > > class Run(models.Model): > > distros = models.ForeignKey('Distro') > > compilers = models.ManyToManyField('Compiler', blank=True, > > null=True) > > adapters = models.ForeignKey('Adapter') > > > > Task = models.IntegerField() > > Path = models.CharField(max_length = 300) > > Date_Time = models.DateTimeField() > > > > class RunForm(ModelForm): > > class Meta: > > model = Run > > > > What I'm trying to do is merely trying to save in the database if the > entry > > does not exist already (hence why I'm trying to use get_or_create). Here > is > > how I'm doing: > > fields = { > > 'Task': task, > > 'Path': runpath, > > 'Date_Time': datetime(2012, 4, 10, 10, 20, 0), > > 'adapters': adapters.id, > > 'distros': distros.id, } > > > > form = RunForm(fields) > > if form.is_valid(): > > runs, created = Run.objects.get_or_create(**form.cleaned_data) > > Try "runs = form.save()", get_or_create doesn't seem to be the correct > method in this situation. > > If you want to skip some fields you can use the form's Meta attributes > to do that. > > - Anssi > > -- > 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. > > -- I'm using Linux because i'm freedom dependent. -- 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.