I have two different different queryset, I want to make union of both queryset
q1 = tbl_nt_123.objects.values_list('id', 'value', 'geometry').filter(restriction='height')\
.exclude(condition_id__in=tbl_conditions.objects.filter(version_id=5).values_list('condition_id',flat=True))
q2 = tbl_network.objects.all().filter(Q(name="height"), Q(state_id=1) | Q(state_id=2)).values_list('id', 'value', 'geometry');
I have tried this function
queryset = (q1) | (q2)
facing this error ' django combine queries on two different base models '
So i have tried two other functions but these are also throwing same exception ' list' object has no attribute 'model' '
queryset = list(q1) + list(q2)
queryset = chain(q1, q2)
Updating my question from here
class tbl_nt_123(models.Model):
condition_id = models.IntegerField(blank=True, null=True)
value = models.FloatField(blank=True, null=True)
geometry = models.GeometryField(blank=True, null=True)
class Meta:
db_table = u'tbl_nt_123'
class tbl_conditions(models.Model):
condition_id = models.IntegerField()
version_id = models.ForeignKey(LookupNavteqversion)
class Meta:
db_table = u'tbl_conditions'
class tbl_network(models.Model):
name = models.CharField(max_length=50, blank=True)
value = models.FloatField()
state_id = models.IntegerField(null=True, blank=True)
geometry = models.GeometryField(null=True, blank=True)
objects = models.GeoManager()
class Meta:
db_table = u'tbl_network'
def __unicode__(self):
return '%s' % self.name
class tbl_networkSerializer(serializers.GeoModelSerializer):
class Meta:
model = tbl_network
fields = ('id', 'value', 'geometry')
Here views file
class NetworkViewSet(viewsets.ModelViewSet):
q1 = tbl_nt_123.objects.values_list('id', 'value', 'geometry').filter(restriction='height')\
.exclude(condition_id__in=tbl_conditions.objects.filter(version_id=5).values_list('condition_id',flat=True))
q2 = tbl_network.objects.all().filter(Q(name="height"), Q(state_id=1) | Q(state_id=2)).values_list('id', 'value', 'geometry');
queryset = list(chain(q1, q2))
serializer_class = tbl_networkSerializer
But both these functions did not return queryset type record.
I want queryset type of tbl_network (q2)
How can i do this?