Yes it has
....
Can you write the query for the above question asked

On Wed, 21 Aug, 2019, 10:51 PM 'Amitesh Sahay' via Django users, <
django-users@googlegroups.com> wrote:

> I am not much of a database guy. But if you wish to get something from
> different table, then there has to be some foreignkey there I guess your
> "courses" table should have CID as foreignkey. May be I am wrong.
>
>
> On Wednesday, 21 August, 2019, 08:26:52 pm IST, Suraj Thapa FC <
> surajthap...@gmail.com> wrote:
>
>
> Thanks...
>
> On Wed, 21 Aug, 2019, 6:24 PM Sundararajan Seshadri, <suns...@gmail.com>
> wrote:
>
> What you need to appreciate is that the foreign key field gives you the
> full record (corresponding to the foreign key).
>
> So, if you fetch all records as course_rating.objects.all() then c.cid
> will also be an object giving you the corresponding foreign key record. So,
> you can access c.cid.cid and c.cid.course_title.(where c is one instance /
> record of the query set)
>
> Some points:
> (a) you are not following the convention. Not a crime. But if you follow
> the convention, it will prove convenient. For example. Courses will be the
> class name. (Table name can be anything)
> (b) You named the foreign-key in the second table as cid, It is, again,
> not an issue but if you followed the convention, you could have called it
> as course so that field names could have been c.course.cid and
> c.course.course_title, probably more meaningful.
>
> Again, convention is for convenience.
>
> Cheers.
> ====================================
> On Wednesday, August 21, 2019 at 2:46:12 PM UTC+5:30, Suraj Thapa FC wrote:
>
> This is my model
>
> class courses(models.Model):
> cid = models.UUIDField(default=uuid.uuid4, editable=True, primary_key=True)
> course_title = models.CharField(max_length=255, default="")
>
>
> class course_rating(models.Model):
> cr_id = models.BigAutoField(primary_key=True)
> cid = models.ForeignKey(courses,on_delete=models.CASCADE)
> userid =
> models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
> rating =
> models.IntegerField(validators[MaxValueValidator(5),MinValueValidator(1)],default=1)
>
>
>
>
> I want to fetch the course_title and cid from courses tables and want to
> perform the average rating of courses
> Can someone write the query set for the same
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f49660db-c157-43df-8563-3e9c2369a8dd%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/f49660db-c157-43df-8563-3e9c2369a8dd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPjsHcHkga3HSeBBTWSaRokmf-qNJq0txwOF6JvwjjsBOg_w_g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPjsHcHkga3HSeBBTWSaRokmf-qNJq0txwOF6JvwjjsBOg_w_g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/393408531.415507.1566408059600%40mail.yahoo.com
> <https://groups.google.com/d/msgid/django-users/393408531.415507.1566408059600%40mail.yahoo.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcFC0fxEEJ0vfjkFH9go4K0AT9B%3D3rrJ9NTHXfH84AKqpw%40mail.gmail.com.

Reply via email to