Problem with get_or_create
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) In the compilers field I don't want to set any value this time. And what I keep getting the following error: int() argument must be a string or a number, not 'list'. Does anyone know why this is happening? Is it not possible to use the get_or_create with many to many relationship in the model? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/utLaEo-7EAkJ. 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.
Re: Newbie Django queryset question
Uhmmm, thank you a lot. That was what I was looking for! Sorry for wasting your time. One last question, does this double-underscore notation work at my html template? Because after filtering I will want to display the information of the different models at one row of my table. On Friday, March 16, 2012 12:09:44 AM UTC-3, Shawn Milochik wrote: > > You can certainly use Q objects to query across models, just as you can > in a normal QuerySet, by using the double-underscore notation. > > > https://docs.djangoproject.com/en/1.3/topics/db/queries/#lookups-that-span-relationships > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/sXps3T_6bDEJ. 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.
Re: Newbie Django queryset question
But if I got it correctly I can use Q objects to make complex filters but they only apply to one model, what I need is a combination of the models. And since the search can return more than one (or even zero) objects I can't use get() to see the related objects. On Thursday, March 15, 2012 9:58:52 PM UTC-3, Shawn Milochik wrote: > > If you don't know which fields your users will be searching on in > advance, you'll have to create Q objects and dynamically build your query > in your view. > > > https://docs.djangoproject.com/en/1.3/topics/db/queries/#complex-lookups-with-q-objects > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/P8Jn4YsOabEJ. 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.
Newbie Django queryset question
Hey guys, sorry if this is a newbie question, but I'm new at django and I'm having a real hard time trying to figure out how to solve this. So I have this model. class Run(models.Model): speccpus = models.ForeignKey('Speccpu') hosts = models.ForeignKey('Host') Task = models.IntegerField() Path = models.CharField(max_length = 300) Date_Time = models.DateTimeField() class Host(models.Model): Name = models.CharField(max_length = 100) ip_addr = models.IPAddressField() admin_ip_addr = models.IPAddressField() Location = models.CharField(max_length = 100) class Speccpu(models.Model): Version = models.CharField(max_length = 50) Base_score = models.IntegerField() Peak_score = models.IntegerField() So what i need to do is search a for an input in any of this fields, so they can return more than one row of a table, since i need to display on the screen a table containing the Run - Task, Path, Date_Time fields, also the Host Name field, and the Speccpu Base and peak score. I was thinking about doing something like an inner join of this three models, and then filtering. But i can't manage to do it. Does anyone have any ideia of how i can do it using the queryset API? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/rEEVGXSHL4AJ. 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.