Thank Mike Dewhirst is working well Cheers
On Fri, Jan 25, 2019 at 6:49 AM 'Amitesh Sahay' via Django users < django-users@googlegroups.com> wrote: > hi, > > All the above should work. If you are working on django REST, then you can > use ModelSerializer helper function. This will automatically sync with the > table fields, and if there are any foreign key and primary key. They would > be mapped automatically. > > Regards, > Amitesh Sahay > *91-750 797 8619* > > > On Friday, 25 January, 2019, 5:44:04 PM IST, Anirudh Jain < > anirudhajain....@gmail.com> wrote: > > > You can do this easily by creating creating an object of that model from > which you want to get the value or input a value by using > 'get_object_or_404' or 'get_list_or_404' by importing from > django.shortucts. Reas about these two functions and difference between > them in documentation. > > Use them, for eg :- > derive = get_object_or_404(ModelChild1, ModelDad=request.user) #object > created of model ModelChild1 > > access = derive.number #will give the value of number that has been input > by user > > On Fri, 25 Jan 2019, 17:29 NAveeN Kumar Reddy < > knaveenkumarredd...@gmail.com wrote: > > You can use this where you want you to link tables with foreign key > > models.ForeignKey(Model_Name,on_delete=models.CASCADE) > > That's it both tables will be in relation after migration of models into > database > > > > On Fri, Jan 25, 2019 at 12:20 PM Mike Dewhirst <mi...@dewhirst.com.au> > wrote: > > On 24/01/2019 5:28 pm, carlos wrote: > > Hello, > > I do not know if I'm asking the question correctly, but I need to call > > a field of one model in another model > > example: > > class ModelDad(models.Model): > > name = blablabla > > > > class ModelChild1(....): > > fk(ModelDad) > > number = models.IntegerField() > > > > class ModelChild2(....): > > fk(ModelDad) > > another_number = models.IntegerField() > > > > def make_proces(self): > > return self.another_number * ModelChild1.number #this is my > question > > > > how can I send a call number within the function (make_proces ) of > > ModelChild2 > > You need a mechanism to find ModelChild1 and the Django ORM provides > Queries for exactly that. > > There is a default model manager called 'objects' which you can use to > find instances of models. By that I mean you can pinpoint a row in the > database table which that model represents. For example ... (but to make > it clearer I'll adjust your models above slightly) > > class ModelDad(models.Model): > name = blablabla > > class ModelChild1(models.Model): > dad = models.ForeignKey(ModelDad) > number = models.IntegerField() > > class ModelChild2(models.Model): > dad = models.ForeignKey(ModelDad) > another_number = models.IntegerField() > > def make_proces(self): > child1 = ModelChild1.objects.get(dad=self.dad) > return self.another_number *child1.number > > Visit Django documentation https://docs.djangoproject.com and scroll > down past "First steps" to "The model layer" and click on a link in the > "Quersets" line. The answers will be in there. > > > > > is posible???? > > > > > > > > -- > > att. > > Carlos Rocha > > -- > > 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 > > <mailto:django-users+unsubscr...@googlegroups.com>. > > To post to this group, send email to django-users@googlegroups.com > > <mailto:django-users@googlegroups.com>. > > Visit this group at https://groups.google.com/group/django-users. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/django-users/CAM-7rO125r3pox%3D137GOfmjnmFaf3cekaNj-j%2B9A0Cwc%3DEM0Fg%40mail.gmail.com > > < > https://groups.google.com/d/msgid/django-users/CAM-7rO125r3pox%3D137GOfmjnmFaf3cekaNj-j%2B9A0Cwc%3DEM0Fg%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 https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/522c40aa-2736-3f57-b23b-9c283c9a59e0%40dewhirst.com.au > . > For more options, visit https://groups.google.com/d/optout. > > > > -- > Naveen Kumar Reddy > > -- > 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 https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CA%2BC2Q82%2Bp47A92koj2%3Djq4aOvFetD%2BEuSikSCSbofTeSxWz-8Q%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CA%2BC2Q82%2Bp47A92koj2%3Djq4aOvFetD%2BEuSikSCSbofTeSxWz-8Q%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 https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAC3mK7exSf7EHZU32OEcoZSb%2BJ1XDyEW0Mz7Prywz8-FYGJAuQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAC3mK7exSf7EHZU32OEcoZSb%2BJ1XDyEW0Mz7Prywz8-FYGJAuQ%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 https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/1747253439.1041432.1548420534962%40mail.yahoo.com > <https://groups.google.com/d/msgid/django-users/1747253439.1041432.1548420534962%40mail.yahoo.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- att. Carlos Rocha -- 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM-7rO0LcQPNzuysCB7iW2C%3D8As2Jn9CDuu%3Dk1zD1JsC4_7RYg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.