Thermopyle posted:I don't have time to type a lot right now, but one aspect of the purpose of putting it on the model or other utility modules is that you can't keep your code more generic by having it in your view. Or (for a very common pattern), what if you want a view that feeds a template for a web app, and then also a Django REST Framework view creating an API for a mobile app? Both need to have the same data properties/methods, but only if you put that code in the model will you be able to avoid writing that logic twice. E: For that matter DRF won't even help you unless your logic is in the model anyway.
|
|
# ? Aug 14, 2017 02:58 |
|
|
# ? Jun 3, 2024 23:46 |
|
I get to start a brand new project at work soon, casting off the shackles of Django1.6 (because holy poo poo) and DRF < 3. The issue is I've now paralysed myself with indecision wondering how best-practice-y to get with it. Do I smash out a cookiecutter-django project template? Use LESS/SASS? Angular 1 or 2? Gulp vs Webpack? I have a fairly solid server-side stack that I'm comfortable with these days, but front-end wise I've been so far off the cutting edge for so long I have no idea where to start. Perhaps this is a question more suited for the modern web-dev thread but I'd like other django users' perspectives on how useful CSS preprocessors/JS toolkits are... Have we reached the point where I don't need to use NPM or Bower anymore?
|
# ? Aug 16, 2017 16:36 |
|
Most people seem to seem to use Django to serve an API that gets consumed by a separate front end project. The front end is built with webpack, react/angular, etc. This is totally valid, and someone with more experience doing it will be along to explain it in depth. If you don't want to go that route, it's still very easy to add modern front end tooling to a django project. I work with a large django project that takes this approach by using webpack to build our JavaScript and CSS. The output directory from the webpack build gets added to STATICFILES_DIRS, so we get all the advantages of modern front end tooling, while keeping all our existing django templates and staticfiles code. This certainly isn't the approach that's en vogue, but it works very well.
|
# ? Aug 16, 2017 16:58 |
|
NtotheTC posted:Have we reached the point where I don't need to use NPM or Bower anymore? This questions seems to presuppose that that is a good and useful direction to go. Personally, I try to use Django to do as little frontend as is possible. In my ideal project, Django serves nothing but an API via DRF, and then I use modern frontend tools like NPM (well, yarn actually), webpack, react, etc.
|
# ? Aug 16, 2017 18:14 |
|
Thermopyle posted:Anyone bought Two Scoops for 1.11 yet? Currently 4 chapters in and I'm loving this book, thanks.
|
# ? Aug 19, 2017 15:53 |
|
Thermopyle posted:Anyone bought Two Scoops for 1.11 yet? Bought it, haven't started reading yet, but I'll give a review when I get a few chapters in.
|
# ? Aug 20, 2017 22:31 |
|
I have a conditional query question. I've been reading https://docs.djangoproject.com/en/1.11/topics/db/aggregation/ and https://docs.djangoproject.com/en/1.11/ref/models/conditional-expressions/ and can't seem to figure this out. Let's say I have an Order model, and I want a payment breakdown grouped by user. Here's the Order model: Python code:
Python code:
pre:User Total -------------- User 1 300 User 2 250 Python code:
pre:User Cash Card Total ---------------------------------- User 1 300 0 300 User 2 200 0 200 User 2 0 50 50 pre:User Cash Card Total ---------------------------------- User 1 300 0 300 User 2 200 50 250 Edit1: The Order model doesn't have default ordering, but just in case, upon reading interaction-with-default-ordering-or-order-by when using values(), I've tried adding .order_by() and .order_by('user') to my query, which did not change the results. Edit2: Here's the SO post, if you care: https://stackoverflow.com/questions/45802068/why-does-case-when-ungroup-the-results-of-my-values-annotate-query epswing fucked around with this message at 17:44 on Aug 21, 2017 |
# ? Aug 21, 2017 04:27 |
Is there a way to force a reversed URL to contain a slash after an optional kwarg in the pattern? I'm doing this: code:
code:
If I make the slash non-optional, then 'account-work' reverses to '/account/work//', and I don't want that. Is there a better way to do this?
|
|
# ? Aug 25, 2017 22:32 |
|
I would argue you shouldn't make them optional if you can. SEO practice is to either always have them or not, and permanent redirect to enforce the scheme, cause technically /thing/ and /thing are two separate URLs. Django even comes with an APPEND_SLASH option, but unfortunately not the reverse which I kinda like.
|
# ? Aug 26, 2017 08:27 |
Yeah, that's my problem. I want it to always have the slash, but I can't seem to do that without the bare "work" URL getting an extra slash, /account/work//.
|
|
# ? Aug 26, 2017 15:03 |
|
I haven't tested this, but wouldn'tcode:
That should still capture the page kwarg cleanly but require the trailing slash to be there.
|
# ? Aug 26, 2017 20:08 |
No dice; says 'account-work' with no arguments doesn't match any patterns. 'account-work' with an arg specified works though.
|
|
# ? Aug 26, 2017 22:14 |
|
How about this?code:
|
# ? Aug 27, 2017 19:04 |
|
You can have more than one route that points to the same view.code:
|
# ? Aug 27, 2017 20:13 |
MonkeyMaker posted:You can have more than one route that points to the same view. ^^ This is byte-for-byte what I ended up doing, but it turns out Pumpkin Pirate's does work too. Nice! It does need the ?: though. Thanks guys!
|
|
# ? Aug 27, 2017 20:44 |
|
epalm posted:
Anyone think this a bug I should be reporting?
|
# ? Aug 29, 2017 15:57 |
|
epalm posted:Anyone think this a bug I should be reporting? I've never used case/when so I'm not sure if its a bug or not, but if I were you I'd report it as a bug only after trying their IRC. When you do report it, you'll either get someone telling you its not a bug and you need to do X, Y, and Z, or it'll be acknowledged as a bug.
|
# ? Aug 29, 2017 16:50 |
|
I was going to get PyCharm with that 30% discount where proceeds go to the Django project, until I remembered that PyCharm is now a "subscription service". I seem to remember the Internet crying about this a year or two ago, and I thought JetBrains went back on it and said "ok ok we'll still offer standalone licenses" but I'm not seeing that option on their site. Is everyone still outraged about this, or is this just how things are nowadays.
|
# ? Sep 5, 2017 21:45 |
epalm posted:I was going to get PyCharm with that 30% discount where proceeds go to the Django project, until I remembered that PyCharm is now a "subscription service". I seem to remember the Internet crying about this a year or two ago, and I thought JetBrains went back on it and said "ok ok we'll still offer standalone licenses" but I'm not seeing that option on their site. You only have to keep paying the subscription fee if you want new versions. Otherwise you can continue to use whatever old version you have. Read more about it here: https://sales.jetbrains.com/hc/en-gb/articles/207240845-What-is-perpetual-fallback-license- It seems like a perfectly reasonable subscription model to me.
|
|
# ? Sep 5, 2017 22:49 |
|
Yeah, it's fine. What is it...something like $60/year? I can't even remember now its so insignificant in the scheme of things.
|
# ? Sep 5, 2017 23:05 |
|
Video talks from DjangoCon 2017 are up. I waffled back and forth about going this year, but I eventually decided not to. After skimming these videos I have to be honest and say I'm glad I didn't go. It seems way too beginner-focused this year which kind of boggles my mind. I would assume there's not a lot of beginners spending $700 or companies sending their junior developers to this thing...
|
# ? Sep 7, 2017 17:30 |
|
Djangocon EU was also an incredible waste of time.
|
# ? Sep 7, 2017 18:48 |
|
Am I being too purist in wanting to separate the Django API backend entirely from the Angluar/whatever/JS frontend? Are there upsides or downsides to having the frontend A) In a completely separate repository (I feel like managing versioning cross-repo could be a hassle) or B) just in a standalone sub-folder within the django project. I don;t particularly want it in the django static files directory for django to serve as there should be no real need. At least not the source js files, does it make sense to have the javascript pre-processor task dump the files into the static folder for live?
|
# ? Sep 13, 2017 11:43 |
|
No, it's a good idea to have your front end and your backend as completely separate projects.
|
# ? Sep 13, 2017 14:04 |
|
Thermopyle posted:No, it's a good idea to have your front end and your backend as completely separate projects. Does it not get irritating having to update two different repos for tiny changes? Or is there a better system than the one i'm imagining where the django project builds the front end project (version x) as part of its deployment.
|
# ? Sep 13, 2017 14:33 |
|
NtotheTC posted:Does it not get irritating having to update two different repos for tiny changes? Or is there a better system than the one i'm imagining where the django project builds the front end project (version x) as part of its deployment. I mean, I guess its slightly less convenient to have to type 'git push' twice, but thats massively outweighed by the clarity of separation of concerns. It really helps keep your API design clean. Besides, I find that once I'm past the brainstorming phase I'll very rarely be jumping back and forth between the two repos. A project I'm working on now is several months in to development and I haven't touched the backend repo in a couple weeks. My deployment for the backend and the frontend is the same system...I push each to github, my CI system picks up that push, runs tests and then deploys to Amazon.
|
# ? Sep 13, 2017 15:20 |
|
NtotheTC posted:Does it not get irritating having to update two different repos for tiny changes? Or is there a better system than the one i'm imagining where the django project builds the front end project (version x) as part of its deployment. I think having a consistent approach to manage cross dependencies (env vars, shared static vars etc) and separate repos is the way to go.
|
# ? Sep 13, 2017 16:21 |
|
I'm two weeks into my new job running the front and back ends completely separately and I must say it's very nice.
|
# ? Sep 18, 2017 22:52 |
|
huhu posted:I'm two weeks into my new job running the front and back ends completely separately and I must say it's very nice. I'm working on a project now where, out of laziness, I went against my normal workflow and I just set up my frontend inside one of my django apps. High on my priority list is undoing that mistake. It didn't really save me much effort to begin with, and now its costing me.
|
# ? Sep 22, 2017 15:16 |
|
code:
|
# ? Sep 27, 2017 03:35 |
Has anybody worked with https://pypi.python.org/pypi/django-pdfkit ? Specifically, I'm having trouble with the rendered page apparently having a race condition where it may or may not be able to pull in all the dependency / include files at render time, like CSS and image files. If it doesn't pull them in in time, the page will render wrong or throw an error, depending. But sometimes it's perfectly fine. I've found that the only way to avoid this is to include all the CSS inline, instead of as a separately linked file, even though the latter is supposed to work fine. Anyone have any experience with this? E: actually I think never mind, this seems to be a problem with wkhtmltopdf, not with Django; I tried another wrapper and it has the same behavior. Fooey. E2: lol i'm just gonna do this code:
Data Graham fucked around with this message at 21:17 on Oct 2, 2017 |
|
# ? Oct 2, 2017 19:57 |
|
Data Graham posted:
The day you forget to commit a static file for those pdfs... "What do you mean the workers are all dead? I'll check the log files oh god"
|
# ? Oct 4, 2017 00:55 |
|
Maybe less a Django question but I'm usually interested in implementing it in a Django context. Is there a list of strategies for keeping change history in fields? I've had a couple toy projects where it would be useful to have snapshots in time, or history when portions were edited. I've played around with having archive flags and creating new objects to link together, but they all have drawbacks. If this is a more general SQL thing I'd be interested in reading up, but haven't hit upon the correct phrase / terms yet.
|
# ? Oct 4, 2017 01:04 |
|
Let's say my Django app needs to generate an image, and save it to disk. Of course, I don't want to do this in a view, I want to push the details of the work (a few id numbers, some text) onto a queue, and process items in the queue sequentially. Many resources seem to point to using redis + celery. Rather than installing and maintaining several new dependencies, why wouldn't I use django-background-tasks (http://django-background-tasks.readthedocs.io/en/latest/)? It seems to just use Django ORM, which it polls "every few seconds". I guess this is considered slow, but for a low-traffic site that doesn't need to blaze through the queue at maximum speed, is there anything else wrong with django-background-tasks?
|
# ? Oct 4, 2017 01:45 |
|
It works super well, it just sucks at scaling.
|
# ? Oct 4, 2017 01:52 |
|
Hed posted:Maybe less a Django question but I'm usually interested in implementing it in a Django context. Audit trails
|
# ? Oct 4, 2017 04:26 |
|
epalm posted:Let's say my Django app needs to generate an image, and save it to disk. Of course, I don't want to do this in a view, I want to push the details of the work (a few id numbers, some text) onto a queue, and process items in the queue sequentially. It works, it just won't scale well. FWIW, I think 90% of people who use celery would be better served by python-rq. It's easier to use and configure. It doesn't support all the advanced features of celery, but like I said the vast majority of people don't need or use those advanced features anyway. Personally, I'd just go with python-rq because redis is easy to install and maintain and I have a strong bias against small projects (python-41 has 4k+ stars on github, django-background-tasks has 117). They're more likely to become un-maintained, less likely to have security issues found and patched, you're less likely to be able to get help, etc...
|
# ? Oct 4, 2017 15:28 |
|
Thermopyle posted:It works, it just won't scale well. I hear you re: github stars. Hard to top a thriving community. When looking for 3rd party apps, the first thing I look at tends to be "date of last commit" on GitHub/BitBucket/etc. RQ looks interesting, however after reading their Docs section, there's one part I don't understand: how do you start the worker process in production? The Starting workers page shows an example running $ rq worker, but... obviously I'm not going to leave an ssh session running with a user logged in after running this command. epswing fucked around with this message at 19:18 on Oct 4, 2017 |
# ? Oct 4, 2017 17:01 |
Thermopyle posted:Personally, I'd just go with python-rq because redis is easy to install and maintain and I have a strong bias against small projects (python-41 has 4k+ stars on github, django-background-tasks has 117). They're more likely to become un-maintained, less likely to have security issues found and patched, you're less likely to be able to get help, etc... python-rq looks pretty cool. I agree with the github stars thing most of the time. Occasionally there is a small project that is very simple and does what I need, like this one I've been using for years that has 66 stars and hasn't been updated since 2015: https://github.com/defrex/django-after-response
|
|
# ? Oct 4, 2017 19:09 |
|
|
# ? Jun 3, 2024 23:46 |
|
Yeah, sometimes you just don't have any choice. I try to look the code over on small, not popular projects and see if I'd be comfortable supporting it myself
|
# ? Oct 4, 2017 19:31 |