How to set the current user on the model instance in the admin:
来源:互联网 发布:模拟灭火 算法 编辑:程序博客网 时间:2024/05/03 14:38
# app/models.pyfrom django.db import modelsfrom django.contrib.auth.models import Userclass Post(models.Model): user = models.ForeignKey(User) content = models.TextField()class Comment(models.Model): post = models.ForeignKey(Post) user = models.ForeignKey(User) content = models.TextField()# app/admin.pyfrom app.models import Post, Commentfrom django.contrib import adminclass CommentInline(admin.TabularInline): model = Comment fields = ('content',)class PostAdmin(admin.ModelAdmin): fields= ('content',) inlines = [CommentInline] def save_model(self, request, obj, form, change): obj.user = request.user obj.save() def save_formset(self, request, form, formset, change): if formset.model == Comment: instances = formset.save(commit=False) for instance in instances: instance.user = request.user instance.save() else: formset.save()admin.site.register(Post, PostAdmin)
- How to set the current user on the model instance in the admin:
- Switch view in the InfoPath form according to the whether current user is in SharePoint group admin
- How to get the current user logged into Sharepoint
- How to set the style in valuelist
- How to set the QT Application icon in the windows.
- How does admin user push down the INI value to normal user
- How to enable the uart log in user version
- svn : how to set the executable bit on a file?
- How to get the current epoch time
- Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection
- How to grant access to SQL logins on a standby database when the guest user is disabled in SQL Serve
- How to allow a user to click on TextBlocks which return an integer ID in the click handler
- How to set bmp for your UserControl in the toolbox
- 161.In your database instance, the user sessions are connected to the database server from the remot
- How to add a user and set environments for the user?
- How to: Access the HTML Source in the Managed HTML Document Object Model
- How to get the current time in milliseconds in C Programming?
- Unable to update database to match the current model!
- 观察者模式【Observer Pattern】
- 指针函数和函数指针的区别
- android 3d游戏研究(二)(边学边写,多谢高手指正,鞠躬) :数据库
- pl/sql中模拟登录Oracle EBS并获得职责 .
- UML类图关系大全
- How to set the current user on the model instance in the admin:
- C++中string erase函数的使用
- 四川一母亲给女儿做30斤香肠当嫁妆感动网友
- 判断输入日期是否合法
- hdu 1012
- QQ表情 双击之后显示gif (像是显示另外一幅图片)--双击有惊喜等
- Oracle Database - System Identifier (SID)
- 常用js脚本验证
- [sicily online]1024. Magic Island