#19271: Form validation throws AttributeError has "Base Model has no attribute
_default_manager"
-----------------------------+---------------------------------------------
     Reporter:               |      Owner:  nobody
  iamrohitbanga@…            |     Status:  new
         Type:  Bug          |    Version:  1.4
    Component:  Forms        |   Keywords:  forms, models, unique constrait
     Severity:  Normal       |  Has patch:  0
 Triage Stage:  Unreviewed   |      UI/UX:  0
Easy pickings:  0            |
-----------------------------+---------------------------------------------
 I have an abstract model BaseModel having a field with unique=True.
 BaseModel obviously has abstract=True.
 Now I create a MyModel which inherits from BaseModel.

 Now I have a view that tries to create a new entry in MyModel with data in
 post request.

 {{{
 #!div style="font-size: 80%"
     def add_new(request, id) {
        myModel = MyModel()          # I am actually creating MyModel
 dynamically but that should not matter
        if request.method == 'POST':
           form = MyModelForm(request.POST)
           if form.is_valid():
               mymodel.field1 = form.cleaned_data['field1']
               mymodel.field2 = form.cleaned_data['field3']
               mymodel.save()
               return render_to_response("mytemplate.html", {'form' :
 form},
                                         RequestContext(request))
           else:
               pass   # return some error here
     }
 }}}

 Now this code works fine when field1 does not have unique=True set but not
 when field1 has unique=True property set.
 When the unique property is set then the form.is_valid() fails. It gives
 an AttributeError. 'BaseModel' object has no attribute '_default_manager'.

 The moment I remove unique=True from my field it works perfectly fine.
 Just a caveat here. I am creating MyModel object dynamically creating the
 object by loading the class dynamically using the approach described here.
 http://stackoverflow.com/a/547867/161628

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19271>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to