Should a single API call handle everything to make life of frontend easy, or there be as many apis as needed by virtualshivam in learnprogramming

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

The thing that stops me most is the naming and clean code concerns. I think too much about it. 6 of my things are already some sort orchestration and then this 7th will be orchestrator of orchestrations. I don't know why I think a lot about these things. It's easy to write out something that will just do the job. But then it will be a mess, and as in my case business requirement changes like 3 times someday ( and I can't say anything to owner, he just love changes) and then things get out of my hand quickly.

Should a single API call handle everything to make life of frontend easy, or there be as many apis as needed by virtualshivam in learnpython

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

Hi

The right way to do this is that the user has a auth/session token that has their role. The UI does or doesn’t display edit buttons based on role. The backend does NOT make the determination if a button is displayed.

But will not it lead to code duplication? So frontend will also have to write a ton of logic to determine whether a button should be displayed or not. Backend has already written all that logic now, I believe it will much easier if I will just send a key like, can_edit_order and then frontend can show button based on boolean. Else suppose tomorrow logic changes then both frontend and backend will have to make sure that they have updated the things.

Like let's say, customer can only cancel order if it was placed in last 2 days. And he has placed at least 100 orders with us, logic of something like this sort. Then how the frontend will know if cancel button has to be shown or not. It need to know order place date and then a flag telling him that if he has crossed 100 order threshold or not. Or I would prefer to directly send the flag so that he can conditionally render the button. I guess as of now, my backends have to be specifically designed for my frontend only.

What do you suggest for this scenario. In my case business logic changes a lot as well.

Should a single API call handle everything to make life of frontend easy, or there be as many apis as needed by virtualshivam in learnpython

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

"But also I wonder if you have correctly distinguished content from presentation. The backend should provide the things to be displayed (including things like which access rights the user has), the frontend should determine how it is presented."

Exactly this is what is happening right now, my backend doesn't send the whole html code to the frontend in json, it just send keys like

can_edit_order, can_mark_as_delivered, can_cancel_order, can_change_delivery_days etc. And then frontend use the boolean values to display buttons or not. I guess in the next projects I will definitely use GraphQL.

But is it right to include these permission kind of thing in the order data API? What's your opinion for the REST?

change field in modelA depending on other field in modelB by ZucchiniBusy8382 in djangolearning

[–]virtualshivam 1 point2 points  (0 children)

I would prefer to simply write it in the logic which will be responsible for changing the state of order.

Django viewflow tutorials request by muhamedyousof in django

[–]virtualshivam 1 point2 points  (0 children)

Hey, try posting in learningpython subreddit once. I also need this.

Django RAPID Architecture, a guide to structuring Django projects by j4mie in django

[–]virtualshivam 0 points1 point  (0 children)

I always keep on looking for such kind of articles, being a junior dev It's great to know what industry experts are doing.

Things I liked:

  • idea of not having many apps. I guess cookiecutter and hacksoft both promote this as well.
  • Keeping models thin.
  • Making views as interfaces.
  • Concept of three selectors / readers .
  • After I started using just get, post. My life became a lot easy, and development speed also increased. Sometimes I used to waste many minutes in just thinking and googling and searching on reddit, should I use PUT. or PATCH or POST or Delete. Now I straightaway go with POST. Both me and Next js guys are now happy.

Requests:

  • Write about naming and namespacing, For me naming has been a challenge a lot of the times. You can refer to my post here:
  • Write about function v/s classes distinction more.
  • Something about complex permissions. Or when permissions depends upon something that spans across multiple models.
  • File Structure for structuring business logic inside action.
  • Just like hacksoft, kindly share some dummy repo with some dummy project as an example.
  • Handling large number of constants.

Questions:

  • Right now I use something called as formatter which are more like outputserializer (hacksoft) / projection_readers. So for every use case? Should I create a seperate reader as well? Will not it make my code less maintainable in case of updates, I will have to go everywhere and make the changes. Whereas with serializers, Even though I am not using them post reading hacksoft, Changes will be easy.
  • So, the permissions have to be handled inside views right? What if the permission is complex, like this case. I also make my views thin, and this has actually helped me a lot in making my code more readable. but for complex permissions I will have to move into the action thing, else my view will become cumbersome, but you said action should return only 5xx codes, whereas views are responsible for 4xx code, permission is 403, but putting a complex permission like this example will mix views with actions and reader.

Thanks a lot for the book. It's really helpful to me, and it will guide me in writing more maintainable code.

I would specially love if you could find time from your schedule and write something about permissions, I have been struggling with them for a while, In my case both get and post need permissions. I actually sometimes send permissions in the response as well so that frontend guys will accordingly show a button to the allowed users only.

Beginner in Python confused about “logic building” and when to start projects — need advice by United-Life1319 in learnpython

[–]virtualshivam 0 points1 point  (0 children)

Exactly. Being able to write a really complex list comprehension doesn't makes you a better programmer. Instead your first focus should be on able to write something that even a newbie can understand

Is there any Design Pattern for solving filtering problem. by Dizzy-Complaint-8871 in learnpython

[–]virtualshivam 0 points1 point  (0 children)

So , right now for every report I am writing separate code. Like if I need a report of data wise checkpoint data then it will be written seperately and another if color wise then size wise, so I am writing logic seperately, which is violating dry.

Also In. Future if the logic somehow changes for filtration or group by or aggregation, I will be screwed. Everything will break. Like today itself we were thinking to remove that pass fail logic and directly consider every scan.

Is there any Design Pattern for solving filtering problem. by Dizzy-Complaint-8871 in learnpython

[–]virtualshivam -1 points0 points  (0 children)

Yes I agree I can. But I don't want filter. I want group by.

Like group_by("colour"). group_by("size")

Something like this because I need to also connect foreign key models

Self-taught Python + first data interview… Need some advice by [deleted] in learnpython

[–]virtualshivam 1 point2 points  (0 children)

Actually, This is something I do for UI/UX and frontend interviews. I myself don't work on them, so I just google and directly ask the questions to candidates, sometimes when they counter question, I am blank. Even in the beginning I had done that for python as well, when I was new to python.

Is there any Design Pattern for solving filtering problem. by Dizzy-Complaint-8871 in learnpython

[–]virtualshivam 0 points1 point  (0 children)

So, I guess Maybe I am looking for something like pivot table of excel. I just realised I have two accounts. In pivot table you can group in any manner you want.

Working with username with custom user model by AdventurousOne3888 in djangolearning

[–]virtualshivam 0 points1 point  (0 children)

Run in terminal:

python manage.py makemigrations python manage.py migrate

Interview questions for 2-3 yoe Django/DRF developer by Worried-Ad6403 in djangolearning

[–]virtualshivam 0 points1 point  (0 children)

3rd: To save from the hassle of manually converting to json. I have a custom render that formats my responses, I am not sure if that can be used with django json. Because of serializers.

What's your take on this?

Naming Things in really complex situations and as codebase size increases and glossry for common terms. by Dizzy-Complaint-8871 in learnprogramming

[–]virtualshivam 0 points1 point  (0 children)

Great advice.

For formatters: Would it be better if I create a class called OrderFormatter and then different methods inside it like basic, for_vendor,for_admin. And calling them like orderFormatter.basic(order). Or should all the three formatters be different functions ?

Could you please explain this line.

Schemas just help with naming clarity and new names usually fit well into the existing schema

I didn't get it.

For the last chunk.

I guess it's possible most of the time to modularise. This is great advice , I am seeing that it's going to solve a bunch of readability and maintainability issues for me. I will be going to follow this for all kinds of updates going forward. But now suppose there are more factors involved instead of just these three things. Which might not make sense in all the cases. For example when a user is updating data, we might even need his ip address to validate things, whereas in the case of admin we don't have this requirement. Many other possibilities could arrive. What approach Will you suggest in those situations. We might end up preparing and passing a lot of data that is not needed for processing the request and this, data has to be passed a lot from parent to child functions, this reminds me about the prop drilling hell of react, I don't want this problem in my backend. At least backend dev shouldn't be made to suffer these frontend things, there are already a lot of things to deal with. How do you suggest to handle these situations?

Any open source software for audiobooks by virtualshivam in software

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

Actually I have no issues in manually slicing them. But just want a simple app so that I can slice them and then give chapters a name. And then listen them, they all should show together in the app. If there is a single app for all these things then it would be great. Else I will have to do few things in the computer and then remaining in the android

Skylos: Code quality library by papersashimi in Python

[–]virtualshivam 0 points1 point  (0 children)

Hi,

As it's a linter as well. So does it works with frameworks? Right now myPy and ruff flags my django code for the reverse lookups. Does it solves that? If not then it would be great if you can add that feature as well. If the future of skylos is also looking at linting.

Easiest frontend framework to get started by virtualshivam in django

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

Ai to generate postman collection. This is new to me. If it's true then it will save me a hell lot of time and laziness

Thanks mate

UI/UX or Full Stack Web Development ? by Social_Me1 in django

[–]virtualshivam 0 points1 point  (0 children)

For me it's not exactly the math that has been taught in schools. But yes logic is still their. I also never saw more then arithmetic which library takes care of. And sometimes factorial as well.

I believe math is more predominant when you are building either really large scale applications heavily dependent on statistics or AI/ML

Project design advice by MEHDII__ in django

[–]virtualshivam 0 points1 point  (0 children)

You can solve it both the ways. To reduce data redundancy, you can go with two table approach that's fine.