Django How to create Django admin with readonly permission for all users? The TLDR answer: We all have encounter situations when someone from the product team asks us to create a model dashboard. With Django admin page, this is just a few lines of code. But what about those scenarios when someone asks for access to a crucial table in the admin
MongoDB What is the select query equivalent in PyMongo/MongoDB native query? The TLDR answer: Coming from the SQL domain, you might stumble upon requirement of writing a select <field_1>, <field_2> from xyz in Mongodb. It might be a little tempting to not use select query, but try to avoid doing it, since it might be
Django How to update multiple fields in Django model efficiently? The TLDR answer: The first answer which you would get when you search django model update on google you would find the .update() Django ORM. While this is great, let us see few points about .update() queryset - * post_save, pre_save signals does not get triggered. While this might
Django How to use Base Model (Inheritance) in Django? The TLDR answer: Once you start creating a serious project in Django you would want to add created_at and updated_at to most of the models. That's when you realise you are not following the Don't Repeat Yourself(DRY) principle by copy-pasting the same field
Django How to disable delete option in Django admin? The TL;DR answer: You need to add a new method has_delete_permission in the Admin class where you want to disable the delete function. from django.contrib import admin class OrganisationAdmin(admin.ModelAdmin): list_display = ("name", "id", "is_active", "domain_name&
Dev tools How to explore Github repo in VS code? The TLDR answer: Though I am not a VS code user, but at times I have been tempted to give it a shot to VS code. Recently I came across something in VS Code which has changed everything for me. I have decided switch to VS code for next 1
Unix How to create a file using shell script (heredoc)? The TLDR answer: If you need to use a shell script which would create a file with the dynamic content using few variables then you can use the code below. The approach we shall take here will use heredoc / here document syntax. cat << EOF > demo.txt cd
React JS How to pass environment variable to Create React App (CRA) ? The TLDR Answer: You need to start the variable name with REACT_APP_ . From the official documentation, you can read more. Your project can consume variables declared in your environment as if they were declared locally in your JS files. By default you will have NODE_ENV defined for you,
Dev Hacks How to get a free domain for lifetime? Freenom can be used to purchase any domain for free. The TDL(Top Domain Level) which freenom allows are tk, ga, ml, cf, gq. You can get the domain free for lifetime.
Dev Hacks How to access member-only Medium stories for free forever? The TLDR answer: I know this is not a tech-related question which you would stumble upon, but I believe, if you are a coder then definitely you read a lot of blogs in medium and a lot of them are members only. Most of the time we would open it
Angular How to get IP address in Angular, React, VueJS, frontend Framework? The TLDR answer: Using a third-party service is the best option possible according to me. One service which I have been using for years is https://jsonip.com. It hasn't let me down until now. Here are the code snippets you can use as per your framework: // If
MongoDB How to check MongoDB ObjectId valid in JS? The TLDR answer: If you are using mongoose as your ORM layer for MongoDB in any of the NodeJS frameworks then one of the simplest and best ways I have come across is if (!mongoose.Types.ObjectId.isValid(object_id)) { throw "Invalid id"; }
Django How to add Custom signals dispatch in Django? Django provides a lot of features out of the box and all of them are production ready and battle tested. But one of the most underrated out of the box features which Django provides is Django signals.
Celery How to setup periodic task in Celery, Django? The TLDR answer: If you using celery for years, then you must have got used to the @periodic_task decorator to help you set up any periodic task. But as soon as you update your celery, you get a deprecation warning, or else if you start using the latest version
UI/UX How to use better code snippet in Ghost Blog platform? The TDLR answer : If you are using the Ghost platform for blogging, chances are you are a coder and write most of your blogs around coding. Though the interface and themes of ghost are configurable if you are someone like me who doesn't want to invest too much
Docker How to configure Webstorm for docker container node_modules? The TLDR answer: The path inside the container has to be /opt/project (exact path) where you are loading the project file and also installing the node_modules. Unfortunately, it is not well documented, and also no way to update the path as of now. The Detailed Answer: If you
Docker How to connect different services between two different docker compose? The TLDR answer: Since you are in two different docker-compose services, you can't use localhost neither you can use the service name. One way is to try using the host machine IP but I have faced issues multiple times. The safest option which has always worked for me
Django How to implement pagination in Django queryset using limit and offset? The TLDR answer: Django utilizes the array slicing syntax of python to implement limit offset. For pagination in Django models, you need to use limit offset. Suppose you have 20 rows in a queryset and you want to access the data in batches of 5. first_five_rows = DBModel.objects.
Dev tools Featured How to write a scrapper/parser using Postman? This blog shows how we can use Postman test script to write a scrapper/ parser using cheerio. Test scripts are executed on server side and not on the webapp/electron powered desktop app, which means you don't need to use your system or a separate server to run the parser.