开发者

Update only some field with create_update.update_object

开发者 https://www.devze.com 2023-02-16 01:17 出处:网络
I\'ve defined a models.py with a \"FirstClass\" which contains a ForeignKey relathionship to \"SecondClass\". The relathionship can\'t be Null.

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

精彩评论

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

关注公众号