Skip to main content
Cambio a español
Origen Enlace

Multiple queries in one view Django Múltiples consultas en una vista

Hi I need some help withnecesito solución a little problemun pequeño problema, I am new to Django and have not mastered it properly yet. I am trying to render a view inestoy tratando de renderizar dos objetos en un pdf, to put you in situation I am going to explain what I need. It is an application to manage properties. Obviously each client can have multiple propertiesla aplicación trata de gestionar propiedades de clientes, obviamente cada cliente puede tener mas de una propiedad. The problem is that when listing the properties of a client it only showsA la hora de hacer la consulta solo me one recordmuestra el primer registro y los demás los omite.

Here my viewMi vista:

Here myLa url

Here myEl html code forde client

And finally myY el html code forde farm

Multiple queries in one view Django

Hi I need some help with a little problem, I am new to Django and have not mastered it properly yet. I am trying to render a view in pdf, to put you in situation I am going to explain what I need. It is an application to manage properties. Obviously each client can have multiple properties. The problem is that when listing the properties of a client it only shows me one record.

Here my view:

Here my url

Here my html code for client

And finally my html code for farm

Múltiples consultas en una vista

necesito solución a un pequeño problema, estoy tratando de renderizar dos objetos en un pdf, la aplicación trata de gestionar propiedades de clientes, obviamente cada cliente puede tener mas de una propiedad. A la hora de hacer la consulta solo me muestra el primer registro y los demás los omite.

Mi vista:

La url

El html de client

Y el html de farm

Origen Enlace

Multiple queries in one view Django

Hi I need some help with a little problem, I am new to Django and have not mastered it properly yet. I am trying to render a view in pdf, to put you in situation I am going to explain what I need. It is an application to manage properties. Obviously each client can have multiple properties. The problem is that when listing the properties of a client it only shows me one record.

Here my view:

def pdf_generation(request, *args, **kwargs):
pk = kwargs.get('pk')
client = Client.objects.get(pk=pk)
farm = Farm.objects.filter(pk=pk)
context = {
    'client': client,
    'farm': farm,
}
html_string = render_to_string('client_pdf.html', context)
html = HTML(string=html_string, base_url=request.build_absolute_uri())
pdf = html.write_pdf(
    stylesheets=[CSS(settings.STATIC_ROOT + '/css/pdf.css')])
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline; filename="export.pdf"'
return response

Here my url

    path('export/<int:pk>', views.pdf_generation, name='client_export_id'),

Here my html code for client

        <tbody>
            <tr>
                <th scope="row">{{ client.id }}</th>
                <th scope="row">{{ client.name }}</th>
                <th scope="row">{{ client.nif }}</th>
                <th scope="row">{{ client.technical }}</th>
                <th scope="row">{{ client.phone }}</th>
                <th scope="row">{{ client.record|date:"j F, Y" }}</th>
            </tr>
        </tbody>

And finally my html code for farm

        <tbody>
            {% for obj in farm %}
            <tr>
                <th scope="row">{{ obj.id }}</th>
                <th scope="row">{{ obj.manager }}</th>
                <th scope="row">{{ obj.farm }}</th>
                <th scope="row">{{ obj.town }}</th>
                <th scope="row">{{ obj.place }}</th>
                <th scope="row">{{ obj.production }}</th>
            </tr>
            {% endfor %}
        </tbody>