我有两个模型:
selectedQueryType
现在使用UpdateView考虑以下示例代码:
class BHA_List(models.Model):
well = models.ForeignKey(WellInfo, 'CASCADE', related_name='bha_list')
bha_number = models.CharField(max_length=100)
class BHA_overall(models.Model):
bha_number = models.ForeignKey(BHA_List, 'CASCADE', related_name='bha_overall')
drill_str_name = models.CharField(max_length=111)
depth_in = models.CharField(max_length=111)
此代码将使用class BHA_UpdateView(UpdateView):
model = BHA_overall
pk_url_kwarg = 'pk_alt'
form_class = BHA_overall_Form
查询BHA_overall
模型实例。但是,我希望pk_url_kwarg = 'pk_alt'
查询pk_url_kwarg = 'pk_alt'
的实例,但是要使用其model = BHA_List
方法来获取get_object()
的实例。有什么办法可以诱骗Django做到这一点?
网址格式如下:
model = BHA_overall
前端看起来像这样:
re_path(r'^bha/(?P<pk_alt>[-\w]+)$', base_views.BHA_UpdateView.as_view(), name='bha')
我需要You can now edit [ BHA 2 ]: # url = .../bha/2
BHA Overall Information -
Drill_str_name: []
Depth_in: []
...
Other Child Model -
other_field: []
other_field: []
来查询pk_url_kwarg = 'pk_alt'
并生成url,但是我仍然需要返回model = BHA_List
对象以显示并允许用户编辑数据。我应该使用什么CBV?有符合我目的的示例代码吗?