Posts

Showing posts from April, 2024

Convert List to string in React

 1.  const myList = [ 'apple' , 'banana' , 'orange' ]; const myString = myList. join ( ', ' ); // Join array elements with ', ' console . log (myString); // Output: "apple, banana, orange" 2. const myList = [ 'apple' , 'banana' , 'orange' ]; const myString = myList. toString (); console . log (myString); // Output: "apple,banana,orange"

Duration between two time in react||JavasScript

    if ( startTime . ampm === endTime . ampm ){           if(startTime.hr>endTime.hr||((startTime.hr===endTime.hr)&&startTime.min>endTime.min))              {               alert("Select Proper Value")              }              else{               var h1=endTime.hr-startTime.hr               if(startTime.hr===endTime.hr){                 var m1=parseInt(endTime.min-startTime.min)               }               else{                 var m1=parseInt(endTime.min)+parseInt(60-startTime.min)               }              ...

Iterate React Component based on an integer value| convert an integer to array

   batchtempinfo. numberoftimeframe > 0 && Array . from ({ length : batchtempinfo. numberoftimeframe }). map ( ( _, index ) => ( < Timeslote key = {index} timeslote = {batchtempinfo.numberoftimeframe} /> )) ///////////////////////////   Array . from ({ length : timeframe }). forEach (( _ , index ) => {                 let t = detailstrainer ( item [ `s ${ index + 1 } trainer` ]);                 console . log ( "trainer details " , t );                 temp . push ( t );             });

How to delete all existing record in django model using terminal

  Using Django shell: Open a terminal. Navigate to your Django project directory. Run the Django shell. python manage.py shell Execute the following commands in the Django shell to delete all records from a specific model: python # Import the model from your_app.models import YourModel # Delete all records YourModel.objects. all ().delete() Make sure to replace YourModel with the name of the model you want to delete records from and your_app with the name of your Django app where the model is defined. Example: Let's say you have a model named Employee in an app named company : python # company/models.py from django.db import models class Employee (models.Model): name = models.CharField(max_length= 100 ) department = models.CharField(max_length= 100 ) # Other fields... To delete all records from the Employee model: python from company.models import Employee Employee.objects. all ().delete()

Reload browser in react/js

  window . location . reload ();

How to create a composite primary Key in django

 To create a composite primary key based on the first three columns ( classdate , course_code , and batch_number ), you need to define a unique_together constraint in the model's Meta class. Here's how you can do it: from django.db import models class DailyWork (models.Model): classdate = models.DateField() course_code = models.ForeignKey(Course, on_delete=models.DO_NOTHING) batch_number = models.ForeignKey(Batch, on_delete=models.DO_NOTHING) s1st = models.CharField(max_length= 7 ) s1endt = models.CharField(max_length= 7 ) class Meta : ordering = [ 'id' ] unique_together = (( 'classdate' , 'course_code' , 'batch_number' ),) In this code, unique_together is a tuple of tuples where each inner tuple represents the fields that should be unique together. In this case, it ensures that the combination of classdate , course_code , and batch_number is unique, effectively creating a composite primary ...

How to check a list contain a value in react

  Using includes() method: javascript const myList = [ 1 , 2 , 3 , 4 , 5 ]; const valueToCheck = 3 ; if (myList. includes (valueToCheck)) { console . log ( 'Value exists in the list' ); } else { console . log ( 'Value does not exist in the list' ); } Using indexOf() method: javascript const myList = [ 1 , 2 , 3 , 4 , 5 ]; const valueToCheck = 3 ; if (myList. indexOf (valueToCheck) !== - 1 ) { console . log ( 'Value exists in the list' ); } else { console . log ( 'Value does not exist in the list' ); } Using find() method: javascript const myList = [ 1 , 2 , 3 , 4 , 5 ]; const valueToCheck = 3 ; if (myList. find ( item => item === valueToCheck)) { console . log ( 'Value exists in the list' ); } else { console . log ( 'Value does not exist in the list' ); }

react variable in tailwind css

let holydaycolor='red-500'   < table > <tbody>                {dateRange.map((item, index) => <tr>           <td className={`text-${holydaycolor}`}> {item}</td> </tr>)}  </tbody> </table>

Date Convert in React

  let x = Date . parse ( "2024-04-08" ) //return date in millisecond let startDate = new Date("2024-04-08");//return date object     x=x+1000 * 60 *60 *24; //one day=1000 * 60 *60 *24 millisecond now x determine next day     startDate=new Date(x);         startDate.getFullYear();//return year     startDate.getMonth()//return month    startDate.getDay()//return Day 0,1,2,3,4,5,6    startDate.getDate()//return Date