﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19271	"Form validation throws AttributeError has ""Base Model has no attribute _default_manager"""	iamrohitbanga@…	nobody	"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.

{{{
    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"	Bug	closed	Forms	1.4	Normal	invalid	forms, models, unique constrait	iamrohitbanga@…	Unreviewed	0	0	0	0	0	0
