On 4/16/14 11:51 PM, Shoaib Ijaz wrote:
I don't want use SQL query in django
OK. You *could* have class B inherit from class A:

class B(A):
  link = models.IntegerField(blank=True, null=True)

and then do your query on A:

ulist = A.objects.all()

hth

                            - Tom


On Thursday, 17 April 2014 04:39:09 UTC+5, Russell Keith-Magee wrote:

    On Wed, Apr 16, 2014 at 9:30 PM, Shoaib Ijaz <shoaib...@gmail.com
    <javascript:>> wrote:
    > Sorry for duplicate post How to create Union
    >
    > I am using Django REST Framework in project and I want to create
    union two
    > different Models.
    >
    > My Models
    >
    > class A(models.Model):
    >     name = models.CharField(max_length=240, blank=True)
    >     geometry = models.GeometryField(blank=True, null=True)
    >     abwrapper= models.ForeignKey(ABWrapper)
    >
    >     class Meta:
    >         db_table = 'tbl_a'
    >
    > class B(models.Model):
    >     name = models.CharField(max_length=240, blank=True)
    >     link = models.IntegerField(blank=True, null=True)
    >     geometry = models.GeometryField(blank=True, null=True)
    >     abwrapper= models.ForeignKey(ABWrapper)
    >
    >     class Meta:
    >         db_table = 'tbl_b'
    >
    > I am trying to create this query
    >
    > SELECT id,name FROM tbl_a UNION (SELECT b.id
    <http://b.id>,b.name <http://b.name> From tbl_b b)
    >
    > My attempt for union
    >
    > a = A.objects.values_list('id')
    > b = B.objects.values_list('id')
    > queryset = a | b


--
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/534FE2D0.1080508%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to