News for hackers. Stuff that matters.
Re:Django Styleguide by dec0dedab0de on Wednesday January 11, 2023 @01:52PM (#34342729)
Always keep your models slim. Don't stuff template ...course_has_finished(course) is not much longer than course.has_finished()

I disagree with this. When trouble shooting or expanding code it is super convenient to import a model and have all of your methods on auto complete. Especially when you need the same functionality in a view, a cron job, a celery task, and an DRF end point.

If you want to keep it clean you can put all your methods in a mixin class and import it from another file.

Also be wary of the formerly South, now built-in migrations stuff.

Things are much better than they were in South. But yes be careful, rule of thumb is always move forward.

Don't use class-based views

Please. For the love of God, always use class based views for almost everything. Almost everything you need is a variant of one of the built in class based views, don't make me read your copy/pasted reimplementation of it.

Re:Django Styleguide by cjohnson318 on Wednesday January 11, 2023 @03:08PM (#34343900)
> Please. For the love of God, always use class based views for almost everything.

This. 100%. Leverage as much pre-built stuff you can, especially with something as important as your HTTP layer. Whenever I run out of CRUD verbs for a model and I need to add a custom endpoint, I'll implement it in a separate APIView sublcass. Convention over configuration; write boring code.

Re:Django Styleguide by asalahli on Wednesday January 11, 2023 @04:11PM (#34344918)
In my view (hehe), Django's class based views is a good idea implemented poorly. In theory you should be able to use any of the built-in class based generic views with minimal customizations to suit your needs, except when you want to do such customizations you're left dealing with a huge inheritance tree of mixins. It's all magic unless you know or wanna read the documentation on what each mixin brings to the view, that is _if_ you know what mixins are involved exactly, of course.
Re:Django Styleguide by collyw on Wednesday January 11, 2023 @05:07PM (#34345693)
Are you aware of https://ccbv.co.uk/? After I discovered that, class based views became easy.
Re:Django Styleguide by adamckay on Wednesday January 11, 2023 @06:35PM (#34346665)
And if you're using DRF there's https://www.cdrf.co/
Re:Django Styleguide by asalahli on Wednesday January 11, 2023 @08:04PM (#34347645)
Wow, 8 years of using Django and I did not know about either of these. Thanks!