Jibin
Jibin

Reputation: 464

invoke data from view after database operation in django

I have a model named "Routing_Dest_Area", i need to get the destinationId from that table and using that value I need to write another query in the same view function itself.I have written the query but don't know how to pass this value to the next query as argument.Pleaae help me to solve .

...models.py.......

class Routing_Dest_Area(models.Model):
    areaDigit = models.IntegerField(primary_key=True)
    destinationId = models.IntegerField()
    destinationName=models.CharField(max_length=30)
    def __str__(self):
        return '%d' % (self.destinationId)

class Routing_Point(models.Model):
    destinationId = models.IntegerField()
    productId=models.CharField(max_length=30)
    routingPointId= models.IntegerField()
    routingPointName=models.CharField(max_length=30)

...view.py.....

def get_route_list(request):
    data={}
    if request.method == "POST":
        areaDigit = request.POST['areaDigit']
        destination_id=Routing_Dest_Area.objects.get(areaDigit=areaDigit)
        data={'test1':Routing_Point.objects.get(destinationId=destination_id)}
    else:
        data = ''
    return render(request, 'routing/test.html',{'data':data})

Upvotes: 0

Views: 28

Answers (1)

ja408
ja408

Reputation: 808

I think what you are after is just getting the id of the query you used in destination_id, if so just add .id or .pk at the end of the query string in destination_id, Routing_Dest_Area.objects.get(areaDigit=areaDigit).id:

def get_route_list(request):
    data={}
    if request.method == "POST":
        areaDigit = request.POST['areaDigit']
        destination_id=Routing_Dest_Area.objects.get(areaDigit=areaDigit).id
        data={'test1':Routing_Point.objects.get(destinationId=destination_id)}
    else:
        data = ''
    return render(request, 'routing/test.html',{'data':data})

Upvotes: 2

Related Questions