Re: How to use subqueries in django
thank you sir i found the solution -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26408019.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
On Wed, Nov 18, 2009 at 2:15 AM, Radhikavkwrote: > > in one query they have giver or conditions > but i need > i wil have one common query like > list=rooms.objects.all() # this is common query i m using > > and if the condition given like room status,type etc then i need to append > those where conditions to the common query > if room_type > append where room_type=this > else > nothing > > i have so many search criteria , i think this appending is useful but it is > giving error queryset has no attribute append > Certainly it is useful, but in the Django ORM it is not done by calling a method named append. It is done by chaining filter calls. Please read: http://docs.djangoproject.com/en/dev/topics/db/queries/#id1 Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
in one query they have giver or conditions but i need i wil have one common query like list=rooms.objects.all() # this is common query i m using and if the condition given like room status,type etc then i need to append those where conditions to the common query if room_type append where room_type=this else nothing i have so many search criteria , i think this appending is useful but it is giving error queryset has no attribute append -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26402998.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
On Nov 17, 2009, at 7:49 AM, Radhikavk wrote: > > hi, > > how to use search criteria using OR and AND in queries > user can search room by no,room_type, block etc i need the combination > > > Please can you refer the tutorial http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects Adam Knight codepoetry - http://www.codepoetry.net/products/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
hi, how to use search criteria using OR and AND in queries user can search room by no,room_type, block etc i need the combination Please can you refer the tutorial -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26390239.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
Karen Tracey-2 wrote: > > On Tue, Nov 17, 2009 at 6:43 AM, Radhikavk <radhi3...@gmail.com> wrote: > >> >> I tried this i dis not get solution >> >> i m getting a list from rooms table >> >> room_list=rooms.objects.all() >> >> This will give me the room type id when i print room_list.room_type_id >> but >> for this id i need a name which is in room_types table >> > > room_list as you have assigned it above won't have a room_type_id so I'm > confused by what you are saying you can do -- what you say you can do > would > produce an error. > > room_list is a QuerySet, you first need to pull an individual instance of > a > rooms model out of the set before you can access any of its attributes > such > as room_type. Once you have a rooms instance, it will have a rooms_type > instance in its room_type attribute. From the rooms_type instance you can > access any of its attributes using standard Python dot notation. For eg: > > for room in room_list: > print 'Room type is: %s' % room.room_type.room_type_name > > If you have not worked through the tutorial I encourage you to do so: > > http://docs.djangoproject.com/en/dev/intro/tutorial01/ > > Also you might find this section of the documentation helpful: > > http://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects > > Karen > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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=. > > > > -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26390136.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
ok i got it Thanks -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26389937.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
On Tue, Nov 17, 2009 at 6:43 AM, Radhikavkwrote: > > I tried this i dis not get solution > > i m getting a list from rooms table > > room_list=rooms.objects.all() > > This will give me the room type id when i print room_list.room_type_id but > for this id i need a name which is in room_types table > room_list as you have assigned it above won't have a room_type_id so I'm confused by what you are saying you can do -- what you say you can do would produce an error. room_list is a QuerySet, you first need to pull an individual instance of a rooms model out of the set before you can access any of its attributes such as room_type. Once you have a rooms instance, it will have a rooms_type instance in its room_type attribute. From the rooms_type instance you can access any of its attributes using standard Python dot notation. For eg: for room in room_list: print 'Room type is: %s' % room.room_type.room_type_name If you have not worked through the tutorial I encourage you to do so: http://docs.djangoproject.com/en/dev/intro/tutorial01/ Also you might find this section of the documentation helpful: http://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
I tried this i dis not get solution i m getting a list from rooms table room_list=rooms.objects.all() This will give me the room type id when i print room_list.room_type_id but for this id i need a name which is in room_types table how to get this Thanks -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26388551.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: How to use subqueries in django
On Nov 17, 10:26 am, Radhikavk <radhi3...@gmail.com> wrote: > Hi , > > I have 2 tables room_types and room > > the table structure > > class room_types(models.Model): > room_type_id = models.AutoField(primary_key=True,null=False,blank=False) > room_type_name = > models.CharField(max_length=100,unique=True,null=False,blank=False) > room_type_desc = models.TextField(null=True) > standard_occupancy = models.IntegerField() > higher_occupancy = models.IntegerField() > base_price = models.DecimalField(max_digits=8, decimal_places=2) > higher_price = models.DecimalField(max_digits=8, decimal_places=2) > status = models.ForeignKey('common.status') > > class rooms(models.Model): > room_no > =models.IntegerField(primary_key=True,null=False,blank=False,unique=True) > room_desc=models.TextField(null=True) > room_type=models.ForeignKey('room_types') > block=models.ForeignKey('blocks') > floor=models.IntegerField() > room_status=models.ForeignKey('room_status') > > Here room_type_id is pk in room_types and is fk in rooms table > > and to display the list of rooms the quesry should be > > select r.room_type_id,r.room_no,rt.room_type_name from room_types rt,rooms r > where rt.room_type_id=r.room_type_id > > How to give this query in django > > Thanks in advance > > -- > View this message in > context:http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p2638... > Sent from the django-users mailing list archive at Nabble.com. You don't need to do anything. Every room has a 'room_type' field so room.room_type. room_type_name will give you the room type name. You can make it a bit more efficient by using select_related when you get the initial queryset. -- 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-us...@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=.
How to use subqueries in django
Hi , I have 2 tables room_types and room the table structure class room_types(models.Model): room_type_id = models.AutoField(primary_key=True,null=False,blank=False) room_type_name = models.CharField(max_length=100,unique=True,null=False,blank=False) room_type_desc = models.TextField(null=True) standard_occupancy = models.IntegerField() higher_occupancy = models.IntegerField() base_price = models.DecimalField(max_digits=8, decimal_places=2) higher_price = models.DecimalField(max_digits=8, decimal_places=2) status = models.ForeignKey('common.status') class rooms(models.Model): room_no =models.IntegerField(primary_key=True,null=False,blank=False,unique=True) room_desc=models.TextField(null=True) room_type=models.ForeignKey('room_types') block=models.ForeignKey('blocks') floor=models.IntegerField() room_status=models.ForeignKey('room_status') Here room_type_id is pk in room_types and is fk in rooms table and to display the list of rooms the quesry should be select r.room_type_id,r.room_no,rt.room_type_name from room_types rt,rooms r where rt.room_type_id=r.room_type_id How to give this query in django Thanks in advance -- View this message in context: http://old.nabble.com/How-to-use-subqueries-in-django-tp26387486p26387486.html Sent from the django-users mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.