samedi 31 janvier 2015

Django how to add value from model into another application's view?


Vote count:

0




I have 2 applications in my "aplikacja" django project:


From articles model I would like to get a value "title" from the first article and then put it into qr.views (it prepares for me a pdf file)


Articles models:



from django.db import models

class Article(models.Model):
title = models.CharField(max_length=150)
content = models.TextField(verbose_name="Zawartosc")
published = models.DateTimeField(verbose_name="Data Publikacji")


How to get a "title" value into qr views? I suppose I need to import article from aplikacja.articles.models. But how to get exactly value in test_qr method?



from reportlab.pdfgen import canvas
from django.http import HttpResponse
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.barcode.qr import QrCodeWidget
from reportlab.graphics import renderPDF
from django.contrib.auth.models import User
from aplikacja.articles.models import article


def test_qr(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'

a= map(lambda x: str(x), User.objects.values_list('id', flat=True).order_by('id'))

p = canvas.Canvas(response)
p.drawString(10, 800, a[1])

qrw = QrCodeWidget(a[1])
b = qrw.getBounds()

w=b[2]-b[0]
h=b[3]-b[1]

d = Drawing(200,200,transform=[200./w,0,0,200./h,0,0])
d.add(qrw)

renderPDF.draw(d, p, 1, 1)

p.showPage()
p.save()
return response


asked 53 secs ago







Django how to add value from model into another application's view?

Aucun commentaire:

Enregistrer un commentaire