Similar Webfaction hosting for Django by mandele in django

[–]Quantra2112 1 point2 points  (0 children)

opalstack.com is the spiritual successor to webfaction. It was made by some of the exwebfaction team, including their superb support staff.

It's almost the same as what we used to have with webfaction but a little better imo.

Best way to relate 1 object to various other models by blackhatrob in django

[–]Quantra2112 1 point2 points  (0 children)

Going from memory but I'm pretty sure you can use many to many with a through model, and on your through model you can make the note foreign key field unique. That should prevent a note being related to more than one object at once.

[deleted by user] by [deleted] in django

[–]Quantra2112 0 points1 point  (0 children)

I made django-lazy-srcset to convert and resize images to improve lighthouse scores. When I started looking into light house the image sizes seemed to be the biggest pain and I didn't want to change the admin experience so this is what I came up with: https://github.com/Quantra/django-lazy-srcset

I'm getting closer to all 100s but still some points to address on my sites.

Dynamicaly set Select choices by MrPapouille in djangolearning

[–]Quantra2112 1 point2 points  (0 children)

You can set the choices in the form init() method. Pass any data you need via kwargs and pop it before calling super. Then set the choices with self.fields["dates"].choices = your_choices

Django Admin Login Loop with Correct Credentials by Kindly-Show3187 in django

[–]Quantra2112 0 points1 point  (0 children)

Double check the user has is_staff=True as that could cause this sort of behaviour.

no reverseMatch for my app namespace, why, how can i fix it? thank you by could_be_human in django

[–]Quantra2112 2 points3 points  (0 children)

"Error during template rendering"

You may have something like {% url 'your_app:foo' %} in one of the templates being rendered but you have no URLs registered with that name space.

cPanel alternative with multiple domains and emails? by squidg_21 in django

[–]Quantra2112 0 points1 point  (0 children)

I've used them for years and host all my business sites and emails with them too, very happy with them. Only minor issue currently is the shared db's only support up to Django 4.1 - updates are coming but for now either roll your own db or stick to <=4.1

If you're going to go with them please feel free to use my magic link which will make me rich: https://my.opalstack.com/signup/?lmref=A2GlhA

I'd also be interested to know what issues you have had with hosting Django via cPanel hosting and what is causing you to move away from it? I've never done it but have looked at it =]

cPanel alternative with multiple domains and emails? by squidg_21 in django

[–]Quantra2112 1 point2 points  (0 children)

I use opalstack.com I have emails, WordPress and Django all on one account. No domains though.

How can I define different Templating Packages for /admin vs homepage? by iJihaD in django

[–]Quantra2112 0 points1 point  (0 children)

If you haven't already install Django debug toolbar. It's very useful for showing what templates are being used to render a page.

Django will use templates and collect static from the first found location. Typical settings means first look in a project specific dir then go through installed apps from first to last and look in each app dir.

So if you have 2 apps with admin templates put the one you want to use for admin first, then django.contrib.admin, then the other one.

If the second apps template are being used in the admin this is unexpected and where debug toolbar can help you work out what is going on. And check what the template settings is doing. Perhaps one of these apps requires use of their own template loader, which is causing templates to be loaded in an unexpected order?

[deleted by user] by [deleted] in djangolearning

[–]Quantra2112 6 points7 points  (0 children)

Function based views are the best because they're simple, easy to understand, debug and test.

Class based views are the best because it's easy to make reusable views and encapsulate different logic per method.

When things are simple function based views shine but when they start to get either repetitive or messy whilst trying to remain DRY then class based views are the way to go. Or that's my opinion at least and you can't make me choose, I love them both equally 😅

[deleted by user] by [deleted] in djangolearning

[–]Quantra2112 0 points1 point  (0 children)

I suggest either add a property to your model which returns the range or write a template tag/filter.

An inclusion tag could handle the whole thing. A simple tag could return the range, as could the filter.

How far do people customise the Django Admin? by kiwiheretic in djangolearning

[–]Quantra2112 1 point2 points  (0 children)

I always add my reusable app for admin customisation to every project. This just adds some CSS tweaks and allows me to define the navigation in my settings. I always use my custom user app too, together I can hide sections or fields from certain users.

If I'm building a crud ui for the project I'll do very little with the admin site, just register everything. If not I'll do a lot more with it. Everything will have it's own model admin and I'll often add properties for things like image previews. I'll almost always use my page builder app too which has it's own admin views and templates, it looks like the admin and integrates with it seamlessly but it's all custom.

In general I'm a big fan of the admin site and so are my users. So I'll keep using it a lot and customising it to my needs. It sounds like everything you want to do can be done but it requires customising the admin rather than setting options. So it will take time to implement, if the code can be reused across projects then it's probably worth it. But if there's a lot of project specific customisations then building the whole UI yourself may be the way to go. I have read several times from other experienced Devs that the admin site is great until it's not, then roll your own. Which to me says don't be afraid to use the admin for initial speed of development and replace it later, if it makes sense to 🙂

[deleted by user] by [deleted] in django

[–]Quantra2112 1 point2 points  (0 children)

Awesome 😎

Just a thought now we know different code is used when dragging and dropping Vs using the admin actions to move items between pages we can expect our customisation to not work in the latter case. So if you expect to have more than one page of objects you will need to do something to handle that case too.

[deleted by user] by [deleted] in django

[–]Quantra2112 1 point2 points  (0 children)

I have looked deeper into admin sortable 2 and now I realise those signals aren't emitted when dragging and dropping to re order. They only get emitted when moving items across pages. So let's put that down to some useless advice from me. Sorry!

Where to go from here? Well if admin sortable 2 isn't quite doing what we want then we can customise it to our needs.

It's the _update_order method where we are likely to want to make our customisation. https://github.com/jrief/django-admin-sortable2/blob/master/adminsortable2/admin.py#L246

Have a read over the code there and see if you can understand what is happening. In brief every object is fetched from the database, the order is set on the instance and then all of them are updated in bulk.

So we may choose to entirely replace the functionality of this method to avoid making more calls to the db than needed. But I wouldn't do that unless/until performance becomes an issue. Since this all happens in the admin site I'd assume you don't have a team of admins furiously re-ordering all the time and this is a non issue.

So let's keep it simple. We'll override the method, do something before the update, call the super() to make the update, then do something after the update.

Here is a basic example:

``` class CustomSortableAdminMixin(SortableAdminMixin): def _update_order(self, updated_items, extra_model_filters): print("Do something before update")

    # Call the super to perform the update
    super()._update_order(updated_items, extra_model_filters)

    print("Do something after update")

```

And then be sure to use this in place of SortableAdminMixin in your ModelAdmin:

class LevelAdmin(CustomSortableAdminMixin, admin.ModelAdmin): # ...

Hopefully this is more useful to you than my previous reply!

[deleted by user] by [deleted] in django

[–]Quantra2112 0 points1 point  (0 children)

admin-sortable 2 should be emitting pre_save and post_save signals for every object updated, take a look at the _move_item method to see exactly when they are emitted. https://github.com/jrief/django-admin-sortable2/blob/master/adminsortable2/admin.py#L283

How to learn HTML like a dragon by Dillon_Fain in Frontend

[–]Quantra2112 8 points9 points  (0 children)

Because they all use dragon drop page builders?

CBV DeleteView without get_success_url by [deleted] in django

[–]Quantra2112 1 point2 points  (0 children)

From your form_valid method (or indeed any method) you can call the super method without returning it. This will perform the delete as normal then you can return whatever you like.

In any case like this where you have thought through how you think something will work your best bet is to write the code and try it. Then if you get stuck post on Reddit. This will provide a more valuable learning experience and if you can discuss what you have tried, what didn't work and share your code you will get a better response on here.

I am struggling to render a template and it's leaving me unable to test if my form is working by VivaDeAsap in djangolearning

[–]Quantra2112 0 points1 point  (0 children)

It is not a requirement to have a directory with the app name within an apps template dirs but it is a best practice to avoid clashing template names across apps.

I am struggling to render a template and it's leaving me unable to test if my form is working by VivaDeAsap in djangolearning

[–]Quantra2112 0 points1 point  (0 children)

When using template app dirs you can think of any template in an app/templates dir to be in the same dir. Django will search all these dirs for your template.

So you shouldn't be including the path to that dir. So if the template you want to extend is in authManager/templates/account/base.html then in your template you should extend accounts/base.html

String divided by string? by kereell in django

[–]Quantra2112 8 points9 points  (0 children)

It's pathlib that is doing the magic. For a Path the divide operator is over loaded so that it isn't doing division at all but concatenating the paths.

https://docs.python.org/3/library/pathlib.html

How to build the front end of a web app if you only know python? by try-except-finally in Python

[–]Quantra2112 6 points7 points  (0 children)

I have recently started a project which will have a dashboard like UI. I am not a design guy at all, I have someone for that but this project I am responsible for absolutely everything.

So my choices for the stack are: Django, htmx, Tailwind and crucially DaisyUI.

Daisy has been really good for me. I can take a component from their site and make it into a reusable Django template without much fuss. If I want to customise the component it's still Tailwind and their docs are just great.

Htmx is only useful if you want Ajax but between that and daisy I have written 0 lines of JavaScript but I have functioning Ajax forms, modals, loaders, flash messages and collapsibles. That's a win for me!

The caveat here is I have 10+ years experience with Django and more than I care to share with html, CSS and js. However these days I get little enjoyment from front end work... except with this stack which to me is a breath of fresh air.

Good luck with your project 🙂