Thursday, August 9, 2018

Re: Django Generic Date Views

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Thu, Aug 09, 2018 at 07:54:29PM +0800, Gerald Brown wrote:
> One thing I discovered is that I had the line for the url.py file in my top
> level url.py.  I moved it to myapp/url.p but still same 404 error, however
> no longer get the "has no attribute" error
>
> How do I call this view?  Tried from the browser
> "http://127.0.0.1:8000/today/" and I get "__init__() takes 1 positional
> argument but 2 were given" error.
>
> Tried "http://127.0.0.1:8000/visit/today/" and I get 404 error.

I'm afraid you're going to need to provide more detail – how about you
post the full traceback that you're getting?

Also, the question which URL is correct is hard to answer unless you
post all the relevant URL configs.

> In the line "queryset = Visit.objects.all()" won't that select all of the
> records in the database when I only want the records for today which I then
> use to create a reportlab pdf file? Prior to trying to use these generic
> date views I was able to generate the file but only for the current date.

You lost me at the part about reportlab, but ``Visit.objects.all()``
does not actually fetch anything from the database yet. It only
returns a QuerySet that can be processed further (you can add more
filter expressions, set ordering, and whatnot), and only fetches data
if you actually evaluate it (for example by iterating over it).

So you'd typically just set that as the ``queryset`` attribute on a
generic view, and then every time the view is executed, it will take
that unevaluated queryset, add all the necessary filters to only
select items for today, and then fetch those.

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJbbC7JAAoJEHA7T/IPM/klCh8P/j9iQowdzLeuTNpz5sQpahiU
KhiePgASItMSnKhwFN5Qv++5eV21dl7fViBFPfkQtQ6hNxJXewX8M7kElvr9dmh3
/8GxmkzrW+yuqBgagzNXHOtMi3zvmrFxkiwR6vKcMoTJUR8jsMFnvvkpeCEqFJas
vj7kCbNPJ26GuIWCvFkmtBf2wpd18L49EuPly88nqt+R5tLNNzZ9h9hHzLB8Jr7f
Lq6m397Rxz9oAk/tXw7XFiOB/tIm3jG77XUGYzhv424qEo9a5R1WFOL+s+MoOkdi
wxdb/WEzk9gxf5+v9HtDI3eRYkqaE1WWXQOe7cGTWlDhW/FPXmuI8dSqQOKYbDCL
bNEzcq/bXpIvy0Ot5Ja4RB7OKXBOyd7QElfkF5TTYCyc9JEH8IavwhAtJlL1S6J9
mkzcUjsv9nTqjPqSBBd0bLrNtm5VCyz731w4KvrSHPVTMPJkplkYDWsf1kL6XPEZ
yybYAlMmNF2RA0MelSAjQw3FNAGK2CEXN0Pq+wja3dZs16zv+Y2vhEUhTgFgVmld
KxGmcoULk05UAsbRqboQMBDubfatUxLuGY4MNKARI39T5vLmuzbwkdlv3T0viFVu
OAKIliDdgYP7yUb3uZI1DK1UhgZKxjHTbLt/Es7yGkXFMRYdvJ7pv6TQ69prjrVp
8B5S03RXDeThmAEffLjr
=erht
-----END PGP SIGNATURE-----

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20180809120842.GJ1181%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment