Posts

Wire decorator in LWC

 The @wire decorator in Lightning Web Components (LWC) is used to establish a connection between a component and its data source, typically an Apex controller method, an imperative Apex method, or a UI API resource. It's a powerful tool for handling data retrieval and synchronization in LWC. Here's a breakdown of how the @wire decorator works and its key features: Declaration : The @wire decorator is declared at the top of the JavaScript class file of an LWC component. Syntax : The syntax for using @wire decorator is:     @wire(wireAdapter, wireAdapterParams) wiredProperty; wireAdapter: The wire adapter specifies the Apex method or UI API resource to call. It can be any valid wire adapter like getRecord, getList, invokeApex, etc. wireAdapterParams: Parameters passed to the wire adapter method, such as recordId, objectApiName, etc. wiredProperty: The property in the JavaScript class where the result of the wire adapter call will be stored. Here are the different ways to us...

What are non field errors in django forms

In Django forms (including ModelForm), non_field_errors are errors that are not associated with any specific form field but are relevant to the form as a whole. These errors occur during form validation and represent issues that apply to the form's data globally rather than to individual fields. non_field_errors are typically used when you need to validate data across multiple fields or when certain conditions must be met across the entire form. For example, you might want to ensure that the form data adheres to some business rules that involve multiple fields or perform checks that require the context of the entire form. Example: Login form if username and password is incorrect then we raise ValidationError that Username or Password is incorrect. This is not related to any field. We have to say that login credentials are incorrect. You can add non_field_errors to a form by raising a ValidationError with the NON_FIELD_ERRORS key. The NON_FIELD_ERRORS key is a special const...

Implicit objects in Django template

In this article we will discuss about implicit objects in Django templates.  In Django templates, there are several implicit objects that are available for use without needing to pass them explicitly from the view. These implicit objects provide access to various context-related information, settings, and functionalities within the template. The most commonly used implicit objects are: {{ request }} : Represents the HttpRequest object that holds information about the current request, including request data, headers, user session, and more. request.GET : A dictionary containing GET parameters sent with the request. request.POST : A dictionary containing POST parameters sent with the request. request.method : The HTTP method used for the request (e.g., "GET", "POST"). request.path : The URL path of the request. request.user : The User object representing the currently authenticated user. request.session : The user's session data.   {{ user }} : P...

Token Authentication in Django rest framework : Using Curl commands

 Create a django-project # Install django and rest_framework pip install django pip install djangorestframework django-admin startprorject token_auth Create a django application # Create an app python manage.py startapp myapi Mention in setting.py # Mention apps in setting.py INSTALLED_APPS = [ '.....', '.....', 'rest_framework', 'rest_framework.authtoken', 'myapi, ] Set Token Authentication Globally (for all views) # Set globally TokenAuthentication in - setting.py REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.BasicAuthentication', # Optional ] } Create a Model # Create a model - models.py from django.db import models from django.contrib.auth.models import User class Blog(models.Model): user = models.ForeignKey(User, on_de...

Basic Data Type and List questions

  Consider a list ( list = [] ). You can perform the following commands: insert i e : Insert integer   at position  . print : Print the list. remove e : Delete the first occurrence of integer  . append e : Insert integer   at the end of the list. sort : Sort the list. pop : Pop the last element from the list. reverse : Reverse the list. Initialize your list and read in the value of   followed by   lines of commands where each command will be of the   types listed above. Iterate through each command in order and perform the corresponding operation on your list. Example : Append   to the list,  . : Append   to the list,  . : Insert   at index  ,  . : Print the array. Output: [1, 3, 2] Input Format The first line contains an integer,  , denoting the number of commands. Each line   of the   subsequent lines contains one of the commands described above. ...