The bottom line: get data from a form and save it into one separate object. created a model:

class Karto(models.Model): id_name = models.IntegerField(default=0) small = models.CharField(max_length=255) file = models.FileField(upload_to='uploads') 

created form:

 class CreateKarto(forms.Form): class Meta(): model = Karto fields = ['small', 'file'] widgets = { 'small': Textarea(attrs={'cols': 80, 'rows': 30}), } 

respectively the form of the template:

 <form action="/dokarto/" method="POST">{% csrf_token %} <label for name="small">Краткое содержание</label> <textarea name="small" cols="80" rows="20"></textarea><br><br> <input type="file" name="file"><br><br> <input type="submit" value="click"> </form> 

and view:

 def create_karto(request): args = {} args.update(csrf(request)) if request.method == 'POST': if request.POST and ("pause" not in request.session): form = CreateKarto(request.POST) if form.is_valid(): instances = form.save() request.session.set_expiry(60) request.session['pause'] = True args['create_done'] = 1 render_to_response('create_docsup.html', args, context_instance=RequestContext(request)) else: redirect('/docsup/', args) else: redirect('/docsup/', args) else: redirect('/docsup/', args) 

Gives an error message

AttributeErroe: 'CreateKarto' object has no attribute 'save' swears at form.save ()

    1 answer 1

    CreateCarto inherited from forms.Form - that is, you create a regular form. It does not have a save() method. You can only use the cleaned_data attribute and rewrite the information from there into your model.

    But in this case, you most likely meant the class CreateKarto(forms.ModelForm) - then everything will work: the form will save the data to a new object.