Thank you. That worked perfectly.
On Sep 8, 1:39 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Sep 8, 7:56 pm, Matt <matt.w...@gmail.com> wrote: > > > > > hey folks, > > > I have two models: > > _______________________________________________________ > > class contentcreator(models.Model): > > name = models.CharField(max_length=50) > > phone = models.CharField(max_length=60, blank=True) > > supervisor = models.CharField(max_length=60) > > department = models.CharField(max_length=60, blank=True) > > def __unicode__(self): > > return self.name > > > class Meta: > > verbose_name = u'Content Creator' > > verbose_name_plural = u'Content Creators' > > > class accuracyreport(models.Model): > > byline = models.ForeignKey(contentcreator, related_name="byline") > > date = models.DateField() > > resolved = models.BooleanField("Resolved?", help_text="Has the > > issue been resolved?", null=True) > > responsible = models.ForeignKey(contentcreator, > > related_name="ultimately_responsible", blank=True, null=True) > > supervisor = models.CharField(max_length=60, editable=False) > > > def save(self): > > if not self.responsible: > > self.supervisor = contentcreator.objects.get > > (name__exact=self.byline).supervisor > > else: > > self.supervisor = contentcreator.objects.get > > (name__exact=self.responsible).supervisor > > super(accuracyreport, self).save() > > _______________________________________________________ > > > The custom save(), as you can probably tell, is where I'm having > > trouble. > > > I'd like to set things so that when the "responsible" field is blank, > > the supervisor of the byline gets saved in the accuracyreport model. > > If it's filled in, then the supervisor of "responsible" gets filled > > in. > > > I'm aware of the denormalization issues, but I think it's the best way > > to handle this particular problem. > > > Help? > > You don't actually say what the problem is. What happens when you save > an object using the code above? > > The main problem that i can see with your code is not with save() > particularly, but with the way you're accessing the related values. > 'self.responsible' is a ForeignKey, so using it as the lookup value > compared to a 'name' field is not likely to work. > > The much easier and more obvious way is to do this: > > if not self.responsible: > self.supervisor = self.byline.supervisor > else: > self.supervisor = self.responsible.supervisor > > -- > DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---