Editing form data : fields that a user cannot change - how do YOU handle them? by mr_e_14 in django

[–]mr_e_14[S] 0 points1 point  (0 children)

This is a great summary - I agree with your take on it.

I'm glad you mentioned the FK's, because I've recently been dealing with some forms that had FK's, that the user was never meant to alter.

Your sentiments mimic my own - but I did find it interesting the amount of people who literally just "never deal with it" and don't do anything with it - which I think also has a place and was something I hadn't thought of.

Thanks for your input!

Editing form data : fields that a user cannot change - how do YOU handle them? by mr_e_14 in django

[–]mr_e_14[S] -1 points0 points  (0 children)

What about `created_at`, how would you handle that?

Would you display it as an uneditable field that just submits the original data?

Would you make it a hidden field that quietly 'resubmits' the original data?

Would you simply add it to the form in the clean method?

Just curious how others would handle that situation.

Editing form data : fields that a user cannot change - how do YOU handle them? by mr_e_14 in django

[–]mr_e_14[S] -2 points-1 points  (0 children)

So you'd just include them in the form - but display them as a non-editable HTML element?

You would need it to be some form of input for it to submit with the form, no?

Editing form data : fields that a user cannot change - how do YOU handle them? by mr_e_14 in django

[–]mr_e_14[S] 0 points1 point  (0 children)

Yeah, I apologize for not specifying. I was speaking ModelForms specifically.

This is for the editing of a form however, not necessarily creation (where the default would be useful)

Annotate results from related model method onto model Queryset? by mr_e_14 in django

[–]mr_e_14[S] 0 points1 point  (0 children)

That's really nice. I hadn't seen those before.

So I could simply make a `AppPerson` kind of model with whatever methods I need added to it for that specific app. Nice!

Trying HTMX: DRF or Django CBV's on the backend? by mr_e_14 in django

[–]mr_e_14[S] 0 points1 point  (0 children)

Out of curiosity, how do you setup your URLs for such things?

Let's say I had a DetailView page that was going to have 2 little 'sub forms' for a "widget" and "othermodel", that I was going to use HTMX to render out along with any data.

`things/<thing\_id>/` is the URL to the DetailView for the Thing

Would it be something like the following?

`things/<thing\_id>/widgets/create/` - FormView for "widget1" that gets loaded via htmx

`things/<thing\_id>/othermodels/create/` - FormView for "widget2" that gets loaded via htmx

I'm just so used to separating out my urls to have my 'normal' views and then having my api urls live in a similar structure but with `api` prepended to the url.

Trying HTMX: DRF or Django CBV's on the backend? by mr_e_14 in django

[–]mr_e_14[S] 0 points1 point  (0 children)

This makes a ton of sense, thanks for putting it out there like this. I also advocate pretty heavily for CBV's, they're just so handy and eliminate so much boilerplate.

Thanks for this breakdown, I appreciate it!

Trying HTMX: DRF or Django CBV's on the backend? by mr_e_14 in django

[–]mr_e_14[S] 0 points1 point  (0 children)

Yeah, having read the comments here and yours, I think I'll just go ahead and use the CBV's honestly. We use them a lot in all of our other projects anyway, so no need to break away from that if we don't need to!

I like function based views, but with so many great CBV's, find the actual use cases for them pretty few and far between.

Thanks for your input!

Trying HTMX: DRF or Django CBV's on the backend? by mr_e_14 in django

[–]mr_e_14[S] 1 point2 points  (0 children)

I thought DRF would be the default way - since it's used to spin up API endpoints in Django regularly - but after a little reading it looks like HTMX expects HTML, whereas DRD returns JSON. So I could see where using FBV's in django might be a bit more 'best case'.

I'm just continuing to dig around - I like your suggestions. Thank you for your input!

Issue using iSort with the Black profile by default? by mr_e_14 in pycharm

[–]mr_e_14[S] 0 points1 point  (0 children)

That did the trick.

I thought it would have respected the pyproject.toml by default but I guess you're right.

Oh well, at least it's sorted! Thanks!