I'm using Django to write an application that will have an interface for automatic requests and similar, which As a graphical / HTML UI now, I will use
POST / addFoo? A = 1 & amp; ModelForm to request such requests like Hello >>
Forms will be added to the database and the form flico (): fu = form.save () returns successful (id = foo.id) if ff for (request) form FIF (request):
Def addFoo (request) Other: Correct fail (code = 0, error = form. Errors) Where successful and fail are appropriate There are functions to generate feedback / Rves entries this part, however, works fine, I would write a similar function editFoo so if the ID of any object 1, POST / editFoo? Id = 1 & amp; A = 42 will change the a field of that object to 42. View function like I currently have def editFoo (request :): try: except foo = models.Foo.objects.get (id = request ['id']): Return If form.is_valid (): form.save () return successful () other: failed to fail (code = 0, error = u'No such object does not exist! ') Form = FooForm (request, example = Foo) 1, error = form.errors) However, when I test this, the unspecified areas which contain error messages in Form.errors are required. Since these requests will be initiated by the client (i.e. I can not pre-load an HTML & lt; form & gt; to edit them), I can not find any way to do this Edit: Models and forms are really simple:
square fu (model): a = integerfilled () b = four variables (max_lamb = 23 ) and
class FooForm (ModelForm): Class Meta: Model = Foo
You will need to use LA which will only contain fields that you are expecting
class FooEditForm (ModelForm): : Class = Meta: Model = Foo Field = ('A',)
Allow field to be omitted:
class FooEditForm (ModelForm): square meta: model = foo A = form. Integerfield (required = false) Code> Category FooEditForm (ModelForm): Square Meta: Model = Foo def __init __ (Self, * args, ** kwargs): Super (FooEditForm, Self) .__ init __ (* Args, ** kwargs) in the field in self.fields. Itervalues (): field.required = False
No comments:
Post a Comment