Posts

Showing posts from November, 2020

Django Hacks

  *  "Hello %s, my name is %s" % ( 'john' , 'mike' ) # Hello john, my name is mike". * *  class Person ( models.Model ): id = models.IntegerField(primary_key= True ) name = models.CharField(max_length= 20 ) def __str__ ( self ): return self. id +self.name class Companies ( models.Model ): title = models.CharField(max_length= 20 ) description=models.CharField(max_length= 10 ) person= models.ForeignKey(Person,related_name= 'persons' ,on_delete=models.CASCADE) Notice the usage of  on_delete=models.CASCADE  in the model Companies. That is to delete all companies when the person that owns it (instance of class Person) is deleted. * My expectation is that the  on_delete=models.SET_NULL  means that if a  User  is deleted, the  Store  will not be deleted. *If you don’t specify  primary_key=True  for any fields in your model, Django will automatically add an  IntegerField  to hold t...