top of page

Django Notes 7: Relational Database Handling

Many-to-One Relationship

In order to perform relation between different models, we can define the field by the following:

customer = models.ForeignKey(Customer, null=True, on_delete=models.SET_NULL)

The on_delete parameter states that the whole instance will be deleted automatically when the customer is deleted.


Many-to-Many Relationship

For the many-to-many relationship, we can define the field by the following:

tags = models.ManyToManyField(Tag)

Then we can store multiple values for a corresponding type of object.




 
 
 

Recent Posts

See All
Create Git Server from my NAS

Recently I am creating a git server in my NAS by following the tutorial here: https://dotblogs.com.tw/bowwowxx/2014/08/14/146249 I have...

 
 
 
Django Notes 8: Query of Database

There are several examples for query the objects in the following: https://github.com/divanov11/crash-course-CRM/blob/Part-8---data-to-te...

 
 
 

Comments


  • Facebook - White Circle
  • Instagram - White Circle
  • LinkedIn - White Circle

© 2017 by Johnny. Make it just for fun.

bottom of page