开发者

Update only some field with create_update.update_object

I've defined a models.py with a "FirstClass" which contains a ForeignKey relathionship to "SecondClass". The relathionship can't be Null. The SecondClass is very expansive (90.000 records), and when i display the FirstClass html form, it requires too many time generating the "select box" field.

Therefore, when I let user update the object (I use create_update.update_objec开发者_如何转开发t generic view), i don't want to display and update the value of the foreignkey field, but i don't know how to do this...


Create a ModelForm and pass it into the view, according to the docs.

Since the foreign key should always exist upon creation, it's safe to ignore it in the update.

class MyModelForm(forms.ModelForm):
    class Meta:
         model = FirstClass
         exclude = ('SecondClass',)

# urls.py
(r'^foo/(?P<object_id>\d+)/$','django.views.generic.create_update.update_object',
                                                 {'form_class': MyModelForm})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜