In Django, how would a database schema look like for a social media site like Instagram? For example, how would you make it so that one user can post multiple posts, and they can only have 1 profile?
Any help is appreciated.
for profiles you add the user as a OneToOneField :
class Profile(models.model):
User=models.OneToOneField ()
Phone = models.CharField(default='', max_length=20)
Zip_code=models.IntegerField(default='')
image = models.ImageField(blank=True,upload_to='users_photos',)
and for post you add the user as a foreign key:
class Post(models.Model):
User=models.ForeignKey(
User,
on_delete=models.CASCADE,
)
....and some other fields you want to add
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.