Add data through admin
To add data content through the admin that comes with django, the operation is as follows:
1. First add data table information to admin.py
from AssetMange import models
admin.site.register(models.Article)
admin.site.register(models.Article2Tag)
admin.site.register(models.ArticleDetail)
admin.site.register(models.Blog)
admin.site.register(models.Category)
admin.site.register(models.Comment)
admin.site.register(models.Tag)
admin.site.register(models.UpDown)
admin.site.register(models.UserFans)
admin.site.register(models.UserInfo)
2. Register the user information of admin:
python3 manage.py createsuperuser
3. Restart the service, visit http://127.0.0.1:8000/admin/ and enter the username and password you just set.
4. The result is as follows:
Add specific data
User added
avatar = models.ImageField(verbose_name='avatar',upload_to='static/imgs/') adds the upload parameter, and then re-migrates the database
The format of the information in the database is as follows:
add blog
def str(self):
return "%s--%s" %(self.user.nickname,self.title)
Add taxonomy type
def __str__(self):
return "%s--%s" %(self.blog.title,self.title)