arnodel wrote: > Hi everyone, > > I am trying to get to grips with django and so far I find it wonderful! > But I am stuck on the following problem, which I have tried to make a > test case of below (see models.py). The problem is that when I try to > add a new parent with some children, then I get an error relating to > the 'toys' field, namely: > > Child' object has no attribute 'set_toys' > > But if I remove the edit_inline argument from the 'mum' field in the > 'Child' object it works fine. It also works fine if I remove the 'toys' > field from the 'Child' object but keep the edit_inline in the 'mum' > field. > > Can I remedy this by changing something (maybe define my own set_toys > methode, but how?) ?
After having had a go at tracing what's going wrong, I have kludged together this solution to my problem by adding the following method to the 'Child' class: class Child(models.Model): [...] def set_toys(self, new_ids): self.toys = [Toy.objects.get(id=new_id) for new_id in new_ids] return True Now everything seems to work fine. Note that the method returns True because where it is needed in the django source it seems to expect a boolean that says whether there was actually a change (I return True because it's the simplest). Is this a bug in django? If so please tell me where to report it. Otherwise I'd be glad to learn how to do things the correct way. > Is there a reason why I shouldn't consider doing things this way? > In short, please enlighten me. > > PS: My version of django advertises itself as "Django version 0.95 > (post-magic-removal)" > > -------------- models.py --------------- > from django.db import models > > > class Toy(models.Model): > name = models.CharField(maxlength=20) > > def __str__(self): > return self.name > > class Admin: > pass > > > class Parent(models.Model): > name = models.CharField(maxlength=20) > > def __str__(self): > return self.name > > class Admin: > pass > > > class Child(models.Model): > name = models.CharField(maxlength=20, core=True) > toys = models.ManyToManyField(Toy) > mum = models.ForeignKey(Parent, edit_inline=models.TABULAR) > > def __str__(self): > return self.name > > class Admin: > pass > ----------------- end of models.py ------------------ -- Arnaud --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---