可以从django admin自定义多个表插入 [英] Can I customize multiple table insertion from django admin

查看:269
本文介绍了可以从django admin自定义多个表插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的models.py:

My models.py :

 class Employee_master(ModelWithoutAppName):
     rec_id = models.AutoField(primary_key=True)
     employee_code = models.CharField(max_length=50)
     employee_name = models.CharField(max_length=50)

 class Employee_wage_details(ModelWithoutAppName):
     rec_id = models.AutoField(primary_key=True) 
     employee_rec =  models.ForeignKey(Employee_master)  
     basic =  models.DecimalField(max_digits=12, decimal_places=2, blank=True, default=0)

我的admin.py:

My admin.py:

 admin.site.register(Employee_master)

现在从管理部分我很容易添加或编辑新记录

Now from the admin section I easily can add or edit new records for

Employee_master 

。现在从admin的同样形式的Employee_master,我想提供选项,给我的输入和插入记录到我的第二个模型

. Now from the same form of Employee_master in admin,I want to provide options to give inputs and insert records to my second model

Employee_wage_details

同时。可能吗?感谢提前

also at the same time. Is it possible? Thanks in Advance

推荐答案

是的,这是可能的。

admin.py 文件:

class Employee_wage_detailsInline:
    model = Employee_wage_details

class Employee_masterAdmin(admin.ModelAdmin):
    inlines = [Employee_wage_detailsInline]

admin.site.register(Employee_master, Employee_masterAdmin)

我推荐 camelcase 为模型名称,如: EmployeeWageDetails

I recommend camelcase for the model name like: EmployeeWageDetails

这篇关于可以从django admin自定义多个表插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆