Re: how can I reference a field from one model to another model

2019-01-25 Thread carlos
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 
> 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
> > .
> > 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-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_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.
> 

Re: how can I reference a field from one model to another model

2019-01-25 Thread 'Amitesh Sahay' via Django users
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 Sahay91-750 797 8619 

On Friday, 25 January, 2019, 5:44:04 PM IST, Anirudh Jain 
 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  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 
> .
> 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-7rO125r3pox%3D137GOfmjnmFaf3cekaNj-j%2B9A0Cwc%3DEM0Fg%40mail.gmail.com
>  
> .
> 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.
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 

Re: how can I reference a field from one model to another model

2019-01-25 Thread Anirudh Jain
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  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 
> 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
>> > .
>> > 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-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_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
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 

Re: how can I reference a field from one model to another model

2019-01-25 Thread NAveeN Kumar Reddy
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 
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
> > .
> > 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-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_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.
For more options, visit https://groups.google.com/d/optout.


Re: how can I reference a field from one model to another model

2019-01-24 Thread Mike Dewhirst

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 
.
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-7rO125r3pox%3D137GOfmjnmFaf3cekaNj-j%2B9A0Cwc%3DEM0Fg%40mail.gmail.com 
.

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.


how can I reference a field from one model to another model

2019-01-23 Thread carlos
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

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.
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-7rO125r3pox%3D137GOfmjnmFaf3cekaNj-j%2B9A0Cwc%3DEM0Fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.