In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Preparatory work:
Windows7-64 bit
Python 2.7
Mysql version: 5.7.12
Django 1.9.5
IDE development tools: pycharm 2.7
Second, design the table structure
The main points involved are:
1. The ER diagram of the table. To design the logic, which tables are there and what attributes each table has?
2. The commonly used fields of models model should be proficient, and the ones used this time are:
CharField
ForeignKey
ImageField
TextField
DateTimeField
BooleanField
IntegerField
ManyToManyField
OneToOneField
# # models.py from _ _ future__ import unicode_literalsfrom django.db import modelsfrom django.contrib.auth.models import User# Create your models here.# post information table class Article (models.Model): title = models.CharField (u "article title", max_length=255,unique=True) category = models.ForeignKey ("Category") Verbose_name=u "plates") head_img = models.ImageField (upload_to= "uploads") content = models.TextField (u "content") auther = models.ForeignKey ("UserProfile") publish_date = models.DateTimeField (auto_now=True) hidden = models.BooleanField (default=True) priority = models.IntegerField (u "priority", default=1000) def _ _ unicode__ (self): return "% (self.title) Self.auther) # comment form class Comment (models.Model): article = models.ForeignKey (Article) user = models.ForeignKey ("UserProfile") parent_comment = models.ForeignKey ('self',related_name='p_comment',blank=True,null=True) comment = models.TextField (max_length=1000) date = models.DateTimeField (auto_now=True) def _ unicode__ (self): return "% (self.comment) Self.user) # likes table class ThumbUp (models.Model): article = models.ForeignKey ('Article') user = models.ForeignKey (' UserProfile') date = models.DateTimeField (auto_now=True) def _ unicode__ (self): return "% (self.auther) # Section Classification Table class Category (models.Model): name = models.CharField (max_length=64 Unique=True) admin = models.ManyToManyField ('UserProfile') def _ _ unicode__ (self): return self.name# user Information Table class UserProfile (models.Model): user = models.OneToOneField (User) name = models.CharField (max_length=32) groups = models.ManyToManyField (' UserGroup') def _ unicode__ (self): return self.name# user Group Table class UserGroup (models.Model): name = models.CharField (max_length=64) Unique=True) def _ _ unicode__ (self): return self.name
3. Add database resource information to settings.py
First of all, you need to create a database called s11bbs in mysql, and then edit settings.py
DATABASES = {'default': {' ENGINE': 'django.db.backends.mysql',' NAME': 's11bbsgiving,' HOST':'', 'USER':'root',' PASSWORD':'123',}}
Fourth, synchronize the database
Cd to the directory where the manage.py file is located
Python manage.py migrate
Python manage.py makemigrations
Python manage.py migrate
Register the database table
If you join in admin.py, you can access the background management interface of django, and you can try to add some test data yourself.
Http://127.0.0.1:8000/admin
# # admin.py from django.contrib import adminimport models# Register your models here.admin.site.register (models.Article,ArticleAdmin) admin.site.register (models.Category,CategoryAdmin) admin.site.register (models.Comment) admin.site.register (models.ThumbUp) admin.site.register (models.UserProfile) admin.site.register (models.UserGroup)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.