Hi, @Vijay you suggestion not working no increment the field_count :/ any other idea
Cheers On Thu, Oct 16, 2014 at 2:44 PM, Vijay Khemlani <vkhem...@gmail.com> wrote: > I think the argument to the F object should be just the name of the field > on ModelA: > > product.field_count = F('field_count') + 1 > > Other than that, there are a few weird things about the code, for example: > > product = ModelA.objects.get(id=self.fk_name.id) > > Why not just use > > product = self.fk_name ? > > On Thu, Oct 16, 2014 at 5:09 PM, carlos <crocha09...@gmail.com> wrote: > >> Hi, i need update a fields the other model i have FK relation >> ok this is my code >> >> ModelA(models.Model): >> name=charfield(...) >> field_count = integerfield() >> ..... >> >> ModelB(models.Model): >> fk_name = FK(ModelA, related_name='models_a') >> # other fields >> .... >> def save(self, *args, **kwargs): >> super(ModelB, self).save(*args, **kwargs) >> if ModelB.objects.filter(fk_name=self.fk_name): >> product = ModelA.objects.get(id=self.fk_name.id) >> print product #this good retrieve this information ModelA >> product.field_count = F('self.fk_name.field_count') + 1 >> product.save(update_fields=['field_count']) >> >> but not working not increment data in my field ModelA fiels_count :( >> >> any help? >> >> i read this doc >> https://docs.djangoproject.com/en/1.6/ref/models/instances/#updating-attributes-based-on-existing-fields >> >> Cheers >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAM-7rO0Xgj3JSJmKPVU_f8Ngj%2Bag-EKzD4j3rQa0bkmUUZ1t4A%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAM-7rO0Xgj3JSJmKPVU_f8Ngj%2Bag-EKzD4j3rQa0bkmUUZ1t4A%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CALn3ei00ren%2BCfXXwtCWcFShPa94LMpWdAU0xPK4tVVNRGxF6g%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CALn3ei00ren%2BCfXXwtCWcFShPa94LMpWdAU0xPK4tVVNRGxF6g%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM-7rO3Rqpb_g_wXdEd5a%2BM4L4Q_4XUn2ciz-eG3V%3DaAWthhtw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.