1from django.db import models
2# Create your models here.
3
4class Contact(models.Model):
5 name = models.CharField(max_length=50)
6 email = models.CharField(max_length=50)
7 contact = models.CharField(max_length=50)
8 content = models.TextField()
9 def __str__(self):
10 return self.name + ' ' + self.email
1The ID in django is a "unique identifier" for each models instances.
2You do not need to explicitly add a ID field to your own models as
3the ID attribute is automatically generated for you behind the scences
4by django for each new model and any newly created instances of that
5model afterwards.
1from django.db import models
2
3class Musician(models.Model):
4 first_name = models.CharField(max_length=50)
5 last_name = models.CharField(max_length=50)
6 instrument = models.CharField(max_length=100)
7
8class Album(models.Model):
9 artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
10 name = models.CharField(max_length=100)
11 release_date = models.DateField()
12 num_stars = models.IntegerField()
13