Posts

Showing posts from September, 2020

Django message framework with bootstrap alert

  1.setting a import koro from  django.contrib.messages  import  constants  as  messages NICHE LIKHO MESSAGE_TAGS = {           messages.ERROR: 'danger' ,          } AIGULA KOERLAM CLASS AR NAME MELANOR JONNO BOOTSTRAP ER SATHE view from  django.shortcuts  import  render from  django.http  import  HttpResponse from  django.http  import  HttpResponseRedirect from  .forms  import  Registry1 from  .models  import  Registry from  django.contrib  import  messages # Create your views here. def   message ( request ):      if  request.method== "POST" :         obj=Registry1(request.POST)          if ...

Django message framework

                                                                  VIEW PART from  django.shortcuts  import  render from  django.http  import  HttpResponse from  django.http  import  HttpResponseRedirect from  .forms  import  Registry1 from  .models  import  Registry from  django.contrib  import  messages # Create your views here. def   message ( request ):      if  request.method== "POST" :         obj=Registry1(request.POST)          if  obj.is_valid():             name=obj.cleaned_data[ 'name' ]         ...

register a model in admin

  from  django.contrib  import  admin from  .models  import  Registry # Register your models here. @admin.register (Registry) class   RegistryAdmin ( admin . ModelAdmin ):     list_display=( 'name' , 'email' , 'password' , 'date' )

override modelform widget

  from  django.forms  import  ModelForm from  .models  import  Registry from  django  import  forms class   Registry1 ( ModelForm ):      class   Meta :         model= Registry         fields=[ 'name' , 'email' , 'password' , 'date' ]         widgets={              'password'  : forms.PasswordInput(),         }

if condition

  //? chrck if condition // var a=6; // var b=8; // if(a<b) // document.write("you are right " + b + " is grater than " , a," modi <br>") // var munna=6 // var soyeb=5 // if((munna==6)&&(soyeb==5)) // document.write("you said true")

Polymorphism method overriding

  #!polymorphism method overriding class   Add :      def   result ( self , d1 , c1 ):          print ( "addission  :"  , d1+c1) class   Multi ( Add ):      def   result ( self , a1 , b1 ):          super ().result( 4 , 4 )      #purber mathod a argument delam          print ( "Multiplication  :"  , a1*b1) obj=Multi() obj.result( 2 , 3 )

Polymorphism method overloading

  #!polymorphism method overloading class   Myclass :                                                    #None hesaba default value delam      def   sum ( self  , a = None  , b = None , c = None ):          if (a!= None   and  b!= None   and  c!= None ):             c=a+b+c          elif (a!= None   and  b!= None ) :             c=a*b                  return ...

Polymorphisom strong and duck typing

  #!polymorphisom strong and duck typing class   Horse :      def   walk ( self ):          print  ( "tabrak tabrak tabrak" ) class   Duck :      def   walk ( self ):          print  ( "tapak thapak thapak" ) class   Cat :      def   talk ( self ):          print  ( "mew mew mew" ) def   funk1 ( obj ):      if   hasattr (obj, "walk" ):           #importent line         obj.walk() d=Duck() funk1(d) h=Horse() funk1(h) c=Cat() funk1(c)

Multiple inheritence

  #! Multiple inheritence #Child class ar bracket er moddhe jai class ar name age likhbo tar priority besy #sobar moddhe super use kora lagbe sun mother father sobar/tahole e  # son bap ma er instance veriable access korte parbe #!Hierarchical Inheritence class   Father :           def   __init__ ( self ):          super (). __init__ ()            # sob classs a super decchi          print ( "Father class Constractor" )      def   showf ( self ):          print ( "Father class instance method" )  ...

Hierarchical Inheritence

  #!Hierarchical Inheritence class   Father :           def   __init__ ( self ):          print ( "Father class Constractor" )      def   showf ( self ):          print ( "Father class instance method" )      class   Son ( Father ):           def   __init__ ( self ):          super (). __init__ ()          print ( "Son class Constractor" )      def   shows ( self ):          print ( "Son class instance method" )      class   Daughter ( Father ):           def   __init__ ( self ):   ...

Multilevel Inheritamce

  #! Multilevel inheritence class   Grandfather :           def   __init__ ( self ):          print ( "GRAND Father class constractor" )           def   showg ( self ):          print ( "grand father class instance mathod" ) class   Father ( Grandfather ):           def   __init__ ( self ):          super (). __init__ ()          print ( "Father class constractor" )           def   showf ( self ):          print ( "father class instance mathod" ) class   Son ( Father ):           def ...

Some work of Super

  #! Some work of super class   Grandfather :           def   __init__ ( self , salary1 ):          self .money=salary1                def   showg ( self ):          print ( "grand father class instance mathod" ) munna=Grandfather( "1 lakh" ) shohan=Grandfather( "50 hazar" ) class   Father ( Grandfather ):           def   __init__ ( self , moneyo ):          self .money=moneyo          super (). __init__ (moneyo)                    def   showf ( self ):          print ( "father class...

Single inheritence with constractor overriding and super keyword

  #! single inheritence with constractor overriding and super keyword """ class Father:          def __init__(self):         self.money="1 lakh"         print("This is parent class constractor")     def show(self):         print("This is parent class Instance method")      class Son(Father):     def __init__(self):         super().__init__()                      #use of super         print("This son class constractor")    ...

Single inheritence with constractor overriding

  #! single inheritence with constractor overriding """Parent class a constractor ache kinthu child class a nai..tahole child  class ar objecr diye parent ar constratcor use amra korachi ....but ... jodi child and parent both class a constractor thake tahole ki  hobe?? tokhon parent er constractor child er jonno karjokori hobe na child ar conostractor parent ar constractor ke replace kore deba aita ka e bole constractor overriding """ class   Father :           def   __init__ ( self ):          self .money= "1 lakh"          self .jomi= "5...

Single inheritance with constracor

  #!single inheritance with constracor class   Faher :     sompotty= "100 biga"           #constractor of parent class      def   __init__ ( self , salary1 ):          self .salary=salary1          print ( "conostractor call hoye galo" ) #now child class class   Son ( Faher ):      #instance method      def   disp ( self ):          #parent ar conostractor er value ke child a instance method a ante pari          print ( "This is a sons instance method  and the salary is" , self .salary)  #Son class ar...

Single inheritance in python

  #! single inheritance in python class   Father :     money= 2000      def   instance ( self , mon1 ):         mon=mon1          print ( "It is instance method" ,mon)      @ classmethod      def   Classmehod ( cls , currency1 ):         currency=currency1          print ( "This is class method and the currency is " ,currency)      @ staticmethod      def   static ( experiment1 ):         experiment=experiment1          print ( "This is static mathod and experiment " ,experiment) class   Son ( Father ...

Nasted class Concept

  """ Nasted class concept """ class   Army :      def   __init__ ( self , name1 ):          self .name=name1      #instance method      def   show ( self ):          print ( "name :" ,  self .name)          print ()      #now inner class banabo      class   Gun :          def   __init__ ( self , capacity1 , length1 ):              self .capacity=capacity1              self .length=length1          def   showgun ( self ):            ...

Passing member of one class to another class

  #!passing member of one classs to another class class   Employee :      #making constractor for taking instance variable      def   __init__ ( self , name1 , id1 ):              self .name=name1          self .id=id1           #Instance method      def   display ( self ):          print ( "employee name" , self .name)          print ( "employee id" , self .id) #notun class banalam class   person :      @ staticmethod      def   show ( me1 ):          print (me1.name)  #me object ka catch kore...

Class Method

  #!class method """ jai mathod diye class variable set kora hoi""" class   Mobile :     r1= "1st"     #class variable      @ classmethod      def   show ( cls , argument ):          cls .r2=argument          print ( cls .r1)          print ( cls .r2)          #class diye class method call korlam,kaj hobe         Mobile.show( "2nd" ) #object banalam realme=Mobile() #object diye class method call korbo,kaj hobe realme.show( "3rd" ) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...

Static method

  #!static mathod """ Sada mathod kono variable set kora jai na...sudhu method ke call kora jai class diye ar object diye""" class   Mobile :     model= "realme"   #class variable      @ staticmethod      def   show ( p ):         price=p   #static variablee set holo          print  ( "price: " ,p) # static method call korlam class diye, kaj hobe Mobile.show( 1000 ) #object banalam realme=Mobile() #object diye call korlam object diye, kaj hobe realme.show( 500 ) #print(realme.price) #?object diye static method ar variable call kora ja nah #print(Mobile.price)  #?class...

Example of constracter

  class   Student :      def   __init__ ( self  , aphone , amodel = "a2" ):          self .phone= "redmi"          self .model=amodel          print ( "costractor has been calld" )      def   auto ( self , price ):          print ( f "phone: {self .phone }   model: {self .model }  price: { price } " ) obj=Student( "realme" , "x2" ) obj.auto( 2000 )

How to take user input

// ?take user input // var a=prompt("give your input:"); // document.write(a);

How to print in python

 print("MUNNA")

Taking user input

  // ?take user input // var a=prompt("give your input:"); // document.write(a);

Send dictionary value direct from url

  URL from  . views  import  index from  django.urls  import  path from  .  import  views urlpatterns = [            path( 'initial/' ,views.initial,{ 'value' : 'ON' }, name = 'initial_name' )     ] view from  django.shortcuts  import  render from  django.http  import  HttpResponse from  django.http  import  HttpResponseRedirect # Create your views here. def   initial ( request , value ):     a=value      print (a)      return  render(request, 'dynamic\initial.html' )

DYNAMIC URL WITH SOME STUDENT INFORMATION (PART-2)

                                                    SOB SAME THAKBE SUDHU VIEW PART from  django.shortcuts  import  render from  django.http  import  HttpResponse from  django.http  import  HttpResponseRedirect # Create your views here. def   initial ( request ):      return  render(request, 'dynamic\initial.html' ) def   index ( request , my_id ):      if  my_id ==  1 : #OR URL <STR> HOLE 1 NA LIKHE '1' AIVABE LIKHBO        dict ={ 'name' : "Munna"  ,  'id' : '181'  ,  'number' :my_id ,  'uni' : 'Daffodil' }           if  my_id ==  2 :       ...