database Archives - Tech Insights Unveiling Tomorrow's Tech Today, Where Innovation Meets Insight Sat, 04 Nov 2023 09:16:06 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/reactconf.org/wp-content/uploads/2023/11/cropped-reactconf.png?fit=32%2C32&ssl=1 database Archives - Tech Insights 32 32 230003556 How to Find All Identity Columns in the Database https://reactconf.org/find-all-identity-columns-in-the-database/ https://reactconf.org/find-all-identity-columns-in-the-database/#respond Sat, 04 Nov 2023 09:16:06 +0000 http://www.sqlneed.com/?p=573 In this article, we will learn How to Find all Identity Columns in the Database. You can typically query the system catalog or information schema, to find identity columns in …

The post How to Find All Identity Columns in the Database appeared first on Tech Insights.

]]>
In this article, we will learn How to Find all Identity Columns in the Database. You can typically query the system catalog or information schema, to find identity columns in different database management systems.

Here’s a Query to find all identity columns in a database.

Using SQL Server to Find All Identity Columns in the Database

SELECT 
	OBJECT_SCHEMA_NAME(tables.object_id, db_id())
	AS SchemaName,
	tables.name As TableName,
	columns.name as ColumnName
FROM sys.tables tables 
	JOIN sys.columns columns 
ON tables.object_id=columns.object_id
WHERE columns.is_identity=1

This query retrieves the table and column names of identity columns in a Database.

Find All identity columns in the database

Another way to find all identity columns in the Database. It contains details of all identity columns in a database along with their seed value, increment value, and other information. The below query for the same is given.

SELECT 
	OBJECT_SCHEMA_NAME(tables.object_id, db_id())
	AS SchemaName,
	tables.name As TableName,
	identity_columns.name as ColumnName,
	identity_columns.seed_value,
	identity_columns.increment_value,
	identity_columns.last_value
FROM sys.tables tables 
	JOIN sys.identity_columns identity_columns 
ON tables.object_id=identity_columns.object_id
Find All Identity Columns in the Database

Read Also:

The post How to Find All Identity Columns in the Database appeared first on Tech Insights.

]]>
https://reactconf.org/find-all-identity-columns-in-the-database/feed/ 0 573
Top 15 SQL Server Management Studio Keyboard Shortcuts and Tips https://reactconf.org/top-15-sql-server-management-studio-keyboard-shortcuts-and-tips/ https://reactconf.org/top-15-sql-server-management-studio-keyboard-shortcuts-and-tips/#respond Wed, 26 Apr 2023 03:45:43 +0000 http://www.sqlneed.com/?p=418 Are you weary of navigating SQL Server Management Studio’s (SSMS) menus and choices? You may save a lot of time and effort by using keyboard shortcuts. We’ll go over the …

The post Top 15 SQL Server Management Studio Keyboard Shortcuts and Tips appeared first on Tech Insights.

]]>
Are you weary of navigating SQL Server Management Studio’s (SSMS) menus and choices? You may save a lot of time and effort by using keyboard shortcuts. We’ll go over the Top 15 SQL Server Management Studio Keyboard Shortcuts and Tips in this article to increase your productivity.

An effective tool for administering SQL Server databases is called SQL Server Management Studio (SSMS). Users can communicate with SQL Server via its graphical user interface (GUI) without having to write any code. However, navigating SSMS with the mouse can be cumbersome and ineffective. Tasks can be completed more quickly and conveniently by using keyboard shortcuts.

 SQL Server Management Studio (SSMS) – what is it?

Users can administer SQL Server databases using the free Microsoft application SQL Server Management Studio (SSMS). For activities like building databases, tables, and stored procedures as well as running queries and managing users, it offers a user-friendly interface.

Why should you utilize keyboard shortcuts?

Keyboard shortcuts enable users to complete activities quickly and efficiently by avoiding the need to travel through menus and options. This saves time and effort, which is especially beneficial for recurring jobs. Keyboard shortcuts also lessen the possibility of errors by requiring less mouse movement and clicking.

More Related Post Calculate Date & Time in SQL Server

Top 15 SSMS Keyboard Shortcuts and Tips

Keyboard shortcuts for opening windows

  • Ctrl+T – Opens a new query window.
  • Ctrl+Shift+N – Opens a new solution.
  • Ctrl+Shift+O – Opens a file.

Keyboard shortcuts for managing tabs

  • Ctrl+Tab – Switches between open tabs.
  • Ctrl+F4 – Closes the current tab.
  • Ctrl+Shift+T – Reopens the last closed tab.

Keyboard shortcuts for executing queries

  • F5 – Executes the query.
  • Ctrl+Shift+M – Executes the query and includes the actual execution plan.
  • Ctrl+R – Toggles the display of the query results pane.

Keyboard shortcuts for formatting code

  • Ctrl+K, Ctrl+F – Formats the entire document.
  • Ctrl+K, Ctrl+D – Formats the current selection.
  • Ctrl+K, Ctrl+C – Comments on the current selection.
  • Ctrl+K, Ctrl+U – Uncomments the current selection.

Keyboard shortcuts for debugging

  • F11 – Toggles a breakpoint on the current line.
  • F5 – Starts debugging.
  • Shift+F5 – Stops debugging.
  • F10 – Steps over the current line.
  • F11 – Steps into the current line.

Keyboard shortcuts for searching and replacing

  • Ctrl+F – Opens the Find dialog.
  • Ctrl+Shift+F – Opens the Find and Replace dialog.
  • F3 – Finds the next occurrence of the current search term.
  • Shift+F3 – Finds the previous occurrence of the current search term.

Keyboard shortcuts for commenting and uncommenting code

  • Ctrl+K, Ctrl+C – Comments on the current selection.
  • Ctrl+K, Ctrl+U – Uncomments the current selection.

Keyboard shortcuts for displaying the execution plan

  • Ctrl+M – Toggles the display of the actual execution plan.

Keyboard shortcuts for managing connections

  • Ctrl+Alt+C – Connects to a database.
  • Ctrl+Alt+D – Disconnects from a database.

Keyboard shortcuts for managing objects

  • F7 – Opens the Object Explorer.
  • F8 – Toggles the display of the Object Explorer Details.

Keyboard shortcuts for managing indexes

  • Alt+F1 – Displays the index details.

Keyboard shortcuts for managing databases

  • Ctrl+D – Opens the Database Properties dialog.
  • Ctrl+Alt+G – Generates a script for a database.

Keyboard shortcuts for managing tables

  • Alt+F1 – Displays the table details.

Keyboard shortcuts for managing views

  • Alt+F1 – Displays the view details.

Keyboard shortcuts for managing stored procedures

  • Ctrl+Shift+M – Executes a stored procedure.
  • Alt+F1 – Displays the stored procedure details.

Conclusion

SSMS keyboard shortcuts can boost your productivity by allowing you to complete activities more quickly and efficiently. We covered the top 15 SSMS keyboard shortcuts and tips in this article, including keyboard shortcuts for opening windows, managing tabs, executing queries, formatting code, debugging, searching and replacing, commenting and uncommenting code, displaying the execution plan, and managing connections, objects, indexes, databases, tables, views, and stored procedures.

The post Top 15 SQL Server Management Studio Keyboard Shortcuts and Tips appeared first on Tech Insights.

]]>
https://reactconf.org/top-15-sql-server-management-studio-keyboard-shortcuts-and-tips/feed/ 0 418
How to Export Data from the Database into Excel using Django Python https://reactconf.org/export-data-from-database-into-excel-using-django/ https://reactconf.org/export-data-from-database-into-excel-using-django/#respond Mon, 18 Jan 2021 15:45:44 +0000 http://labpys.com/?p=274 In this tutorial, we will learn how to Export Data from the Database into Excel using Django. In this Django application, I used the pandas library. Let’s start Install  pandas …

The post How to Export Data from the Database into Excel using Django Python appeared first on Tech Insights.

]]>
In this tutorial, we will learn how to Export Data from the Database into Excel using Django. In this Django application, I used the pandas library.

Let’s start

Install  pandas library

First, create a Django project, then create models

Django Export Data From Database into Excel

models.py

from django.db import models
from Django import forms 

class tbl_Employee(models.Model):    
  #  Id = models.IntegerField()
    Empcode = models.CharField(max_length=10, default='')
    firstName = models.CharField(max_length=150,null=True)
    middleName = models.CharField(max_length=100,null=True)    
    lastName = models.CharField(max_length=100,null=True)
    email = models.CharField(max_length=30,null=True)
    phoneNo = models.CharField(max_length=12, default='',null=True)
    address = models.CharField(max_length=500, default='',null=True) 
    exprience = models.CharField(max_length=50, default='',null=True)        
    DOB = models.DateField(null=True, blank=True)   
    gender = models.CharField(max_length=10, default='',null=True)
    qualification = models.CharField(max_length=50,default='',null=True)   
    
     

    def __str__(self):
        return self.firstName
                
    objects = models.Manager()

let's migrate model
python manage.py makemigrations
python manage.py migrate
 

forms.py

 
from django import forms

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, Row, Column, Field

from .models import  tbl_Employee

class EmployeeRegistration(forms.ModelForm):
    class Meta:
        model = tbl_Employee
        fields =[ 'Empcode','firstName','middleName','lastName','email','phoneNo' ,'address','exprience',
                  'DOB','gender','qualification'
        ] 

Then let’s write a code in views.py to create a function to Export data from the database into Excel.

Views.py

from .models import tbl_Employee
import datetime as dt
import pandas as pd
import os
from django.conf import settings
from django.core.files.storage import FileSystemStorage

import csv
 
def export_users_csv(request):
   
    
    if request.method == 'POST':
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="EmployeeData.csv"'         
        writer = csv.writer(response)
        writer.writerow(['Employee Detail'])       
                
        
        writer.writerow(['Employee Code','Employee Name','Relation Name','Last Name','gender','DOB','e-mail','Contact No' ,'Address' ,'exprience','Qualification'])

        users = tbl_Employee.objects.all().values_list('Empcode','firstName' , 'middleName' , 'lastName','gender','DOB','email','phoneNo' ,'address','exprience','qualification')
        
        for user in users:
            writer.writerow(user)
        return response

    return render(request, 'exportexcel.html')

 then add the path to  the urls file

urls.py

from django.urls import path
from . import views

urlpatterns = [
    path("",views.base,name="base"),
    path("user_login/",views.user_login,name="user_login"),

 

    path('export_users_csv/', views.export_users_csv,name="export_users_csv"),  
     
    
]

Create a template folder in the root directory or app directory and a create html file named exportexcel.html

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> 
{% block content %}
<div class="shadow-lg continer">
<form method="post" enctype="multipart/form-data">
    {% csrf_token %}

    <div class="row">
        <div class="col-md-6 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
              <h2>Data Export</h2>
           
              <div class="clearfix"></div>
            </div>
            <div class="x_content">
<div class="row">
              <div class="col-md-8 col-sm-12 col-xs-12 form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-6" for="name">Company<span class="required">*</span>
                </label>
               
              </div>
            </div>
              <button type="submit" class="btn btn-success" >Export</button>                            
                            </div>
                        </div>
                    </div>
                </div>
  </form>
  </div>
   
{% endblock %}
Then execute command 
Python manage.py runserver 



See More: Import Data from Excel into Database using Django

The post How to Export Data from the Database into Excel using Django Python appeared first on Tech Insights.

]]>
https://reactconf.org/export-data-from-database-into-excel-using-django/feed/ 0 321
Import Data from Excel into Database using Django https://reactconf.org/import-data-from-excel-into-database-using-django/ https://reactconf.org/import-data-from-excel-into-database-using-django/#comments Mon, 18 Jan 2021 15:32:42 +0000 http://labpys.com/?p=269 Spreadsheets are commonly used by businesses and organizations to collect and retain data in today’s digital age. However, as the amount of data increases, these spreadsheets can become challenging to …

The post Import Data from Excel into Database using Django appeared first on Tech Insights.

]]>
Spreadsheets are commonly used by businesses and organizations to collect and retain data in today’s digital age. However, as the amount of data increases, these spreadsheets can become challenging to manage. That is where databases come in. Importing data from an Excel spreadsheet into a database is simple with Django, a high-level Python web framework. In this tutorial, we’ll learn how to import data from Excel into a Django database.

Create Django project 

We need to create a Django project  Import_Excel

     Django-admin startproject  Import_Excel

Create Django App

Now then we will create a app  import_excel_db  to perform import data from excel into database.

python  manage.py startapp import_excel_db

Install pandas and Django-import-export Library

Pandas 
 pip install pandas
Django-import-export
 pip install Django-import-export

Configure  Application Settings

Configure application settings by registering the App_name into the settings.py in a specific location at INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'import_excel_db',
]

Create the Model

Now we need to create an employee model.

from django.db import models

# Create your models here.

class Employee(models.Model):       
    Empcode = models.CharField(max_length=10, default='')
    firstName = models.CharField(max_length=150,null=True)
    middleName = models.CharField(max_length=100,null=True)    
    lastName = models.CharField(max_length=100,null=True)
    email = models.CharField(max_length=30,null=True)
    phoneNo = models.CharField(max_length=12, default='',null=True)
    address = models.CharField(max_length=500, default='',null=True)     
    DOB = models.DateField(null=True, blank=True)   
    gender = models.CharField(max_length=5, default='',null=True)
    qualification = models.CharField(max_length=50,default='',null=True) 
    salary = models.FloatField(max_length=50,default='',null=True)   
    
    def __str__(self):
        return self.firstName
                
    objects = models.Manager()

Create the resource file

Import data from Excel into the database using the Django-import-export library and this library works with the concept of Resource. So we need to create a resources.py file in the app folder.

from import_export import resources
from .models import Employee

class EmployeeResource(resources.ModelResource):
    class Meta:
        model = Employee

Django File Upload

from http.client import HTTPResponse
from django.shortcuts import render 
import os
from django.core.files.storage import FileSystemStorage
 
 
# Create your views here.

def Import_Excel_pandas(request):
    
    if request.method == 'POST' and request.FILES['myfile']:      
        myfile = request. FILES['myfile']
        fs = FileSystemStorage()
        filename = fs.save(myfile.name, myfile)
        uploaded_file_url = fs.url(filename)    
        return render(request, 'Import_excel_db.html', {
            'uploaded_file_url': uploaded_file_url
        })   
    return render(request, 'Import_excel_db.html',{})

Create the views functions

views.py

Importing data from Excel into database using Pandas library

from http.client import HTTPResponse
from django.shortcuts import render
import pandas as pd
import os
from django.core.files.storage import FileSystemStorage
from .models import Employee

# Create your views here.

def Import_Excel_pandas(request):
    
    if request.method == 'POST' and request.FILES['myfile']:      
        myfile = request. FILES['myfile']
        fs = FileSystemStorage()
        filename = fs.save(myfile.name, myfile)
        uploaded_file_url = fs.url(filename)              
        empexceldata = pd.read_excel(filename)        
        dbframe = empexceldata
        for dbframe in dbframe.itertuples():
            obj = Employee.objects.create(Empcode=dbframe.Empcode,firstName=dbframe.firstName, middleName=dbframe.middleName,
                                            lastName=dbframe.lastName, email=dbframe.email, phoneNo=dbframe.phoneNo, address=dbframe.address,
                                            gender=dbframe.gender, DOB=dbframe.DOB,salary=dbframe.Salary )           
            obj.save()
        return render(request, 'Import_excel_db.html', {
            'uploaded_file_url': uploaded_file_url
        })   
    return render(request, 'Import_excel_db.html',{})

Importing data from excel into database using  import-export library

from tablib import Dataset
from .Resources import EmployeeResource

def Import_excel(request):
    if request.method == 'POST' :
        Employee =EmployeeResource()
        dataset = Dataset()
        new_employee = request.FILES['myfile']
        data_import = dataset.load(new_employee.read())
        result = EmployeeResource.import_data(dataset,dry_run=True)
        if not result.has_errors():
            EmployeeResource.import_data(dataset,dry_run=False)        
    return render(request, 'Import_excel_db.html',{})

Provide Routing (URL patterns)

We need to add import_excel_db.urls to project urls.py

Urls.py

from django.contrib import admin
from django.urls import path,include
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('import_excel_db.urls')),
]

Create urls.py file inside import_exceldb app to write the URL pattern or providing routing for the application.

urls.py

from django.urls import path
from . import views  
from Import_Excel import settings
from django.conf.urls.static import static
urlpatterns =[
path("",views.Import_Excel_pandas,name="Import_Excel_pandas"),
path('Import_Excel_pandas/', views.Import_Excel_pandas,name="Import_Excel_pandas"), 
path('Import_excel',views.Import_excel,name="Import_excel"),
] 
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root = settings.STATIC_ROOT)

Static Root Configuring

import os
STATIC_ROOT =  os.path.join(BASE_DIR, "assets")

Create Template

Create a template folder inside import_exceldb app and create html file in the directory.

import_excel_db.html

{% block content %}
  <form method="POST" enctype="multipart/form-data">
    {% csrf_token %}

    <div class="row">
        <div class="col-md-6 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
              <h2>Import Excel Data into Database</h2>           
              <div class="clearfix"></div>
            </div>
            <div class="x_content">
              <div class="col-md-8 col-sm-12 col-xs-12 form-group">      
              </div>
                    <input type="file" name="myfile" class="form-control">
                             <button type="submit" class="btn btn-success" >Upload data using Pandas</button> 
                             <button type="submit" class="btn btn-success" >Upload data using Import_Export_Lib</button>   
                            </div>
                        </div>
                    </div>
                </div>
  </form>   
{% endblock %}
Now make migrations
 Python manage.py makemigrations
Python manage.py migrate
Python manage.py runserver
Document

More Related Posts



The post Import Data from Excel into Database using Django appeared first on Tech Insights.

]]>
https://reactconf.org/import-data-from-excel-into-database-using-django/feed/ 10 320
Execute the CRUD Operation in Django with SQLite Database https://reactconf.org/how-to-execute-the-crud-operation-in-django/ https://reactconf.org/how-to-execute-the-crud-operation-in-django/#respond Mon, 18 Jan 2021 12:30:14 +0000 http://labpys.com/?p=246 In this tutorial, we will learn how to do CRUD Operations using Django with SQLite Database. In this tutorial, we will Create, Retrieve, Update, and delete records from a database …

The post Execute the CRUD Operation in Django with SQLite Database appeared first on Tech Insights.

]]>
In this tutorial, we will learn how to do CRUD Operations using Django with SQLite Database. In this tutorial, we will Create, Retrieve, Update, and delete records from a database table. So, we will see a step-by-step procedure to do this.

After Creating the Django App let’s create a model that contains table name and fields

http://labpys.com/how-to-create-login-page-using-django-python/

models.py

from django.db import models
from Django import forms 

class tbl_Companydetails(models.Model):
  #  Id = models.IntegerField() 
    companyName =  models.CharField(max_length = 150)
    Address = models.CharField(max_length = 500)
    contactNo = models.CharField(max_length=15)
    establisheddate = models.DateField(null=True, blank=True)
    websitelink = models.CharField(max_length=50,default='')
    emailaddress = models.CharField(max_length=50,default='')   
  #  companylogo =models.FileField()

    def __str__(self):
        return self.companyName
    ddlcompanyobjects = models. Manager()

After creating model then create forms.py file

from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, Row, Column, Field

from .models import tbl_Companydetails

class Companymaster(forms.ModelForm):
    class Meta:
        model = tbl_Companydetails
        fields=['companyName','Address','contactNo','establisheddate','websitelink','emailaddress']

creating model execute commands  

python manage.py makemigrations

python manage.py migrate

Then create a method to retrieve and insert data in a database table using view.

Views.py

from django.shortcuts import render,redirect
from django.contrib.auth import login,authenticate
from .models import tbl_Authentication,tbl_Companydetails
from .forms import Companymaster
from django.shortcuts import render, redirect ,get_object_or_404 
from django.contrib import messages 

def CreatecompanyNew(request):
    ddlcompanyobjects= tbl_Companydetails.ddlcompanyobjects.all()

    if request.method == 'POST':
        form = Companymaster(request.POST)
        print(form.errors,form)
        if form.is_valid(): 
            user = form.save(commit=False)                
            user.save()                
            return render(request,'company.html',{'form':form,'ddlcompanyobjects':ddlcompanyobjects})
    else:
        form = Companymaster()
    return render(request,'company.html',{'form':form,'ddlcompanyobjects':ddlcompanyobjects})

edits existing records

def Editcompany(request, id):      
    ddlcompanyobjects = tbl_Companydetails.ddlcompanyobjects.get(id=id)      
    return render(request,'EditCompany.html', {'ddlcompanyobjects':ddlcompanyobjects})  

 
def Updatecompany(request, id):
        print('t')          
        obj= get_object_or_404(tbl_Companydetails, id=id)       
        form = Companymaster(request.POST, instance= obj)
        context= {'form': form}
        print(obj)
        if form.is_valid():
            ddlcompanyobjects = tbl_Companydetails.ddlcompanyobjects.all()               
            user = form.save(commit=False)      
            user.save()       
            messages.success(request, "You successfully updated the Data")
            context= {'form': form}                           
            return render(request, 'company.html',{'form':form,'ddlcompanyobjects':ddlcompanyobjects})
        else:
            context= {'form': form,
                           'error': 'The Data  was not updated successfully.'}
            return render(request,'company.html' , context)

Delete a record in the table

def Deletecompany(request, id): 
    ddlcompanyobjects = tbl_Companydetails.ddlcompanyobjects.get(id=id)       
    ddlcompanyobjects.delete()
    return redirect('/CreatecompanyNew')

After that  add the path to urls.py files

from django.urls import path
from . import views

urlpatterns = [
    path("",views.base,name="base"),
 

    path('CreatecompanyNew/',views.CreatecompanyNew,name='CreatecompanyNew'),
    path('Editcompany/<int:id>', views.Editcompany,name="Editcompany"),
    path('Updatecompany/<int:id>', views.Updatecompany,name="Updatecompany"), 
    path('Deletecompany/<int:id>', views.Deletecompany,name="Deletecompany"), 
    
]

Once writing views and models is over then move to the templates folder to create html page named Company.html, here I am using Django with boostrap4.

{%  block title %} Company {%  endblock %} 
 
{% block content %} 

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<form method="POST"  enctype = "multipart/form-data" >
{% csrf_token %}
<div class="container shadow-lg">
<div class="row">
        <div class="col-md-12 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
              <h2>Company Details</h2>
           
              <div class="clearfix"></div>
            </div> 
            <div class="row">
                  <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-6 col-sm-3 col-xs-12" for="name">Company Name <span class="required">*</span>
                    </label>
                    <input type="text" name="companyName" class="form-control" pattern="^[^\s][\w\W]*$" autocomplete="off"
                    title="Enter Company Name. Dont Use Space At Start and Special Characters, You can use a combination of Alphabets and Numbers."
                    minlength="1" maxlength="50" onkeypress="return (event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123) || (event.charCode == 32)"/> 
                   </div>

                   <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Address<span class="required">*</span>
                    </label>
                    <input type="text" name="Address" class="form-control" /> 
                   </div>      
            </div>          
            <div class="row">
                   <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Contact No<span class="required">*</span>
                    </label>
                    <input type="text" name="contactNo" class="form-control" pattern="[0-9]{10}"
                               autocomplete="off"
                               title="Enter Contact Number."
                               minlength="10" maxlength="10"
                        onkeypress="return (event.charCode >= 48 && event.charCode <= 57)"/> 
                   </div>

                   <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-4 col-sm-3 col-xs-12" for="name">Established date<span class="required">*</span>
                    </label>
                    <input type="date" name="establisheddate" class="form-control" /> 
                   </div>
                            
            </div>

            <div class="row">
              <div class="form-group col-md-6 mb-0">
               <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Website URL<span class="required">*</span>
               </label>
               <input type="text" name="websitelink" class="form-control" /> 
              </div>

              <div class="form-group col-md-6 mb-0">
               <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Email address<span class="required">*</span>
               </label>
               <input type="text" name="emailaddress" class="form-control" /> 
              </div>
                       
       </div>

       <div class="row"> 
       </div>
       <br/>
            <div class="form-group">
              <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                <button type="submit" class="btn btn-success">Submit</button>
               <button class="btn btn-primary" type="reset">Reset</button>               
              </div>
            </div>
          </div>

          <div class="x_content">
            <div id="datatable_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
              <div class="row">
                <div class="col-sm-12">
                  <table id="datatable" class="table table-striped table-bordered dataTable no-footer"
                    role="grid" aria-describedby="datatable_info">            

        <thead>
            <tr role="row">
              <th hidden="true">SLNO</th>
              <th>Company Name</th>
              <th>Address</th>
              <th>Contact No</th>
              <th>Established Date</th>
              <th>Email</th>
              <th>Website Url</th>
              <th>Action</th>              
            </tr>
          </thead>
      
      <tbody>
        {% for company in ddlcompanyobjects %}
          <tr style="background:#f8fcff">
            <td class="align-middle" hidden="true">{{ company.id   }}</td>
            <td class="align-middle" >{{ company.companyName   }}</td>
            <td class="align-middle">{{ company.Address  }}</td> 
            <td class="align-middle">{{ company.contactNo  }}</td> 
            <td class="align-middle">{{ company.establisheddate  }}</td> 
            <td class="align-middle">{{ company.emailaddress   }}</td> 
            <td class="align-middle">{{company.websitelink}} </td>
            <td>
                <a  href="/Editcompany/{{ company.id }}"><i class="fa fa-pencil"></i>Edit</a>
                 <a href="/Deletecompany/{{ company.id }}"><i class="fa fa-trash-o"></i>Delete</a> 
              </td>
       
          </tr>

        {% empty %}
          <tr>
            <td class="bg-light text-center font-italic" colspan="4">No Data</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
          </div>
        </div>
            </div>
          </div>
        </div>
</div> 
</div>
</form>
{% endblock %}

Editcompany.html

{%  block title %} Company {%  endblock %}

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> 

{% block content %}
 
 
<form method="POST"  action="/Updatecompany/{{ ddlcompanyobjects.id }}" enctype = "multipart/form-data" >
{% csrf_token %}
<div class="container shadow-lg">
<div class="row">
        <div class="col-md-12 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
              <h2>Company Details</h2>
           
              <div class="clearfix"></div>
            </div> 
            <div class="row">
                  <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-6 col-sm-3 col-xs-12" for="name">Company Name <span class="required">*</span>
                    </label>
                    <input type="text" name="companyName" class="form-control" value="{{ ddlcompanyobjects.companyName }}" 
                    pattern="^[^\s][\w\W]*$" autocomplete="off"
                    title="Enter Company Name. Dont Use Space At Start and Special Characters, You can use a combination of Alphabets and Numbers."
                    minlength="1" maxlength="50" onkeypress="return (event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123) || (event.charCode == 32)"/> 
                   </div>

                   <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Address<span class="required">*</span>
                    </label>
                    <input type="text" name="Address" class="form-control" value="{{ ddlcompanyobjects.Address }}"/> 
                   </div>     
            </div>           
                   <div class="row">
                   <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Contact No<span class="required">*</span>
                    </label>
                    <input type="text" name="contactNo" class="form-control" value="{{ ddlcompanyobjects.contactNo }}"
                    pattern="[0-9]{10}"
                               autocomplete="off"
                               title="Enter Contact Number."
                               minlength="10" maxlength="10"
                        onkeypress="return (event.charCode >= 48 && event.charCode <= 57)"/> 
                   </div>

                   <div class="form-group col-md-6 mb-0">
                    <label class="control-label col-md-4 col-sm-3 col-xs-12" for="name">Established date<span class="required">*</span>
                    </label>
                    <input type="date" name="establisheddate" class="form-control" value="{{ ddlcompanyobjects.establisheddate|date:"Y-m-d"}}" /> 
                   </div>
                            
            </div>

            <div class="row">
              <div class="form-group col-md-6 mb-0">
               <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Website URL<span class="required">*</span>
               </label>
               <input type="text" name="websitelink" class="form-control" value="{{ ddlcompanyobjects.websitelink }}" /> 
              </div>

              <div class="form-group col-md-6 mb-0">
               <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Email address<span class="required">*</span>
               </label>
               <input type="text" name="emailaddress" class="form-control" value="{{ ddlcompanyobjects.emailaddress }}"/> 
              </div>
                       

       </div>
       <div class="row">

       
       </div>
        <br/>
            
            <div class="form-group">
              <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                <button type="submit" class="btn btn-success">Submit</button>
               <button class="btn btn-primary" type="reset">Reset</button>               
              </div>
            </div>
          </div>
        
        </div>
</div>
</div>
 
</form>
{% endblock %}

then execute command

python manage.py runserver



The post Execute the CRUD Operation in Django with SQLite Database appeared first on Tech Insights.

]]>
https://reactconf.org/how-to-execute-the-crud-operation-in-django/feed/ 0 319