hello Karen,
below is the code required. I hope you can help me =)
thanks in advance
Thiago
here is the FEATURE MODEL unique property
#
# Fields that should be unique together in the database.
#
unique_together = [("featureId", "pf", "intComponent", "db",
"pd")]
here is the def searchFeature in the views.py
#*****************************************************************************************************************************************************************
# searchFeature
#*****************************************************************************************************************************************************************
def searchFeature(request, view = None):
if request.method == 'POST':
form = SearchFeatureForm(request.POST)
if form.is_valid():
# Perform the query
ftrQuery = Feature.objects.all().order_by('featureId',
'pk')
# Remove empty fields and start filtering
if request.POST.__getitem__('featureId') != "":
ftrQuery = ftrQuery.filter(featureId__contains =
request.POST.__getitem__('featureId')).distinct()
if request.POST.__getitem__('name') != "":
ftrQuery = ftrQuery.filter(name__icontains =
request.POST.__getitem__('name')).distinct()
if request.POST.__getitem__('pf') != "":
ftrQuery = ftrQuery.filter(platform =
request.POST.__getitem__('pf')).distinct()
if request.POST.__getitem__('state') != "":
ftrQuery = ftrQuery.filter(state =
request.POST.__getitem__('state')).distinct()
if request.POST.__getitem__('db') != "":
ftrQuery = ftrQuery.filter(drumbeat__pk =
request.POST.__getitem__('db')).distinct()
if request.POST.__getitem__('intComponent') != "":
ftrQuery = ftrQuery.filter(intComponent =
request.POST.__getitem__('intComponent')).distinct()
if request.POST.__getitem__('estimator') != "":
ftrQuery = ftrQuery.filter
(estimate__estimator__name__icontains = request.POST.__getitem__
('estimator')).distinct()
if request.POST.__getitem__('ftrStartYear') != "":
ftrStartYear = int(request.POST.__getitem__
('ftrStartYear'))
if request.POST.__getitem__('ftrStartMonth') != "":
ftrStartMonth = int(request.POST.__getitem__
('ftrStartMonth'))
if request.POST.__getitem__('owner') != "":
ftrQuery = ftrQuery.filter(owner__pk =
request.POST.__getitem__('owner'))
if request.POST.__getitem__('pd') != "":
ftrQuery = ftrQuery.filter(product__contains =
request.POST.__getitem__('pd'))
from datetime import date
if request.POST.__getitem__('ftrStartYear') != "" and
request.POST.__getitem__('ftrStartMonth') != "":
ftrQuery = ftrQuery.filter(date__gte = date
(ftrStartYear, ftrStartMonth, 1)).distinct()
if request.POST.__getitem__('teamMember') != "":
role = request.POST.__getitem__('memberRole')
if role == "ANY":
role = ""
ftrQuery = ftrQuery.filter(Q
(teammember__employee__name__icontains = request.POST.__getitem__
('teamMember')) & Q(teammember__role__contains = role)).distinct()
actualEffortLow = 0
actualEffortHigh = 0
if request.POST.__getitem__('actualEffortLow') != '':
actualEffortLow = int(request.POST.__getitem__
('actualEffortLow'))
if request.POST.__getitem__('actualEffortHigh') != '':
actualEffortHigh = int(request.POST.__getitem__
('actualEffortHigh'))
if request.POST.__getitem__('actualEffortLow') != '' or
request.POST.__getitem__('actualEffortHigh') != '':
ftrQuery = ftrQuery.filter(Q(actual__type__contains=
'effort') & Q(actual__actual__gte = actualEffortLow) & Q
(actual__actual__lte = actualEffortHigh)).distinct()
actualSizeLow = 0
actualSizeHigh = 0
if request.POST.__getitem__('actualSizeLow') != '':
actualSizeLow = int(request.POST.__getitem__
('actualSizeLow'))
if request.POST.__getitem__('actualSizeHigh') != '':
actualSizeHigh = int(request.POST.__getitem__
('actualSizeHigh'))
if request.POST.__getitem__('actualSizeLow') != '' or
request.POST.__getitem__('actualSizeHigh') != '':
ftrQuery = ftrQuery.filter(Q
(actual__type__contains='size') & Q(actual__actual__gte =
request.POST.__getitem__('actualSizeLow')) & Q(actual__actual__lte =
request.POST.__getitem__('actualSizeHigh'))).distinct()
queryTeamSizeLow = request.POST.__getitem__('teamSizeLow')
queryTeamSizeHigh = request.POST.__getitem__
('teamSizeHigh')
#Only way I could find to select with COUNT without
writting the SQL code.
if queryTeamSizeLow != '':
for item in ftrQuery:
if item.teammember_set.count() < int
(queryTeamSizeLow):
ftrQuery = ftrQuery.exclude
(featureId=item.featureId)
if queryTeamSizeHigh != '':
for item in ftrQuery:
if item.teammember_set.count() > int
(queryTeamSizeHigh):
ftrQuery = ftrQuery.exclude
(featureId=item.featureId)
queryNumDepsLow = request.POST.__getitem__('numDepsLow')
queryNumDepsHigh = request.POST.__getitem__('numDepsHigh')
if queryNumDepsLow != '':
for item in ftrQuery:
if item.dependency_set.count() < int
(queryNumDepsLow):
ftrQuery = ftrQuery.exclude
(featureId=item.featureId)
if queryNumDepsHigh != '':
for item in ftrQuery:
if item.dependency_set.count() > int
(queryNumDepsHigh):
ftrQuery = ftrQuery.exclude
(featureId=item.featureId)
if request.POST.__getitem__('dependency') != "":
for item in ftrQuery:
if item.dependency_set.filter
(dependency__name__contains = request.POST.__getitem__
('dependency')).count() == 0:
ftrQuery = ftrQuery.exclude
(featureId=item.featureId)
return render_to_response('ftrTool/searchFtr.html',
{'view':view, 'form': form, 'ftrQuery': ftrQuery},
context_instance=RequestContext
(request))
else:
form = SearchFeatureForm()
return render_to_response('ftrTool/searchFtr.html', {'view':view,
'form': form},
context_instance=RequestContext(request))
Here is the form definition
#*****************************************************************************************************************************************************************
# Search Feature Form.
#*****************************************************************************************************************************************************************
class SearchFeatureForm(forms.ModelForm):
# Default parameters, overriding required attribute to false.
featureId = forms.IntegerField(required = False,
widget=forms.TextInput(attrs={'size':'5'}))
name = forms.CharField(required = False)
platform = forms.ChoiceField(required = False, choices =
FORM_QUERY_PLATFORM_CHOICES)
drumbeat = forms.ModelChoiceField(Drumbeat.objects.all(),
required = False)
intComponent = forms.ChoiceField(required = False, choices =
FORM_QUERY_COMPONENT_CHOICES)
product = forms.CharField(required = False)
owner = forms.ModelChoiceField(Component.objects.all(),
required = False)
devType = forms.ChoiceField(label = "Development Type",
required = False, choices = FORM_QUERY_DEV_TYPE_CHOICES)
state = forms.ChoiceField(required = False, choices =
FORM_QUERY_STATE_CHOICES)
#Extra Parameters For Query
actualSizeLow = forms.IntegerField(label="Actual Size",
required = False, widget=forms.TextInput(attrs={'size':'3'}))
actualSizeHigh = forms.IntegerField(label="Actual Size",
required = False, widget=forms.TextInput(attrs={'size':'3'}))
actualEffortLow = forms.IntegerField(label="Actual Effort",
required = False, widget=forms.TextInput(attrs={'size':'3'}))
actualEffortHigh = forms.IntegerField(label="Actual Effort",
required = False, widget=forms.TextInput(attrs={'size':'3'}))
teamMember = forms.CharField(label="Team Member", required =
False, widget=forms.TextInput(attrs={'size':'25'}))
memberRole = forms.ChoiceField(label = 'As', choices =
FORM_QUERY_ROLE_CHOICES, required = False)
estimator = forms.CharField(label="Estimator", required =
False)
teamSizeLow = forms.IntegerField(label="Team Size", required
= False, widget=forms.TextInput(attrs={'size':'3'}))
teamSizeHigh = forms.IntegerField(label="Team Size", required
= False, widget=forms.TextInput(attrs={'size':'3'}))
#** ftrStartYear = forms.IntegerField(label="Year", required =
False, max_value=2100, min_value=2000, widget=forms.TextInput(attrs=
{'size':'5', 'maxlength':'4'}))
#** ftrStartMonth = forms.IntegerField(label="Month", required =
False, max_value=12, min_value=1, widget=forms.TextInput(attrs=
{'size':'2', 'maxlength':'2'}))
ftrStartYear = forms.IntegerField(label="Year", required =
False, max_value=2100, min_value=2000, widget=forms.TextInput(attrs=
{'size':'5', 'max_length':'4'}))
ftrStartMonth = forms.IntegerField(label="Month", required =
False, max_value=12, min_value=1, widget=forms.TextInput(attrs=
{'size':'2', 'max_length':'2'}))
numDepsLow = forms.IntegerField(label="Number of
Dependencies", required = False, widget=forms.TextInput(attrs=
{'size':'3'}))
numDepsHigh = forms.IntegerField(label="Number of
Dependencies", required = False, widget=forms.TextInput(attrs=
{'size':'3'}))
dependency = forms.CharField(label = "Dependency", required
= False, widget=forms.TextInput(attrs={'size':'25'}))
class Meta:
model = Feature
exclude = ('date','description', 'wikiLink')
Post by Karen TraceyPost by Thiago F. CrepaldiHello,
I am migrating a system from django 0.97 (svn) to 1.0.2 (stable) and I
'RelatedObject' object has no attribute 'unique'
I recreated all tables through 'python manage.db syncdb' command and
imported all the old data back again.
Just FYI, this is not necessary to migrate from .9x to 1.0.2. Tables from
.9x installations work perfectly well with 1.0.x.
Post by Thiago F. CrepaldiIt looks like that all unique indexes declared were created correctly
on the MySQL database.
In fact, I didn't even understand what this error means. Can someone
help me out ?
It would be easier to help if you shared the code you have in your
ftrTool\views.py searchFeature function, as well as the form definition you
are using. All I can say from the traceback below is that the unique
validation code is finding it's got a RelatedObject object where it is
expecting to have something else. Whether that is a bug in your code or in
the unique validation code is hard to say without seeing your code.
Karen
Post by Thiago F. CrepaldiI already read
http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/
and
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges
and, unfortunately, had no luck =/
Request Method: POST
Request URL:http://localhost:8000/ftrTool/searchFeature/
Django Version: 1.0.2 final
Python Version: 2.5.2
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'webTool.ftrTool']
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware')
File "C:\PYTHON25\Lib\site-packages\django\core\handlers\base.py" in
get_response
86. response = callback(request, *callback_args,
**callback_kwargs)
File "D:\thiago\dados\eclipse_workspace\webTool\..\webTool\ftrTool
\views.py" in searchFeature
File "C:\PYTHON25\Lib\site-packages\django\forms\forms.py" in is_valid
120. return self.is_bound and not bool(self.errors)
File "C:\PYTHON25\Lib\site-packages\django\forms\forms.py" in
_get_errors
111. self.full_clean()
File "C:\PYTHON25\Lib\site-packages\django\forms\forms.py" in
full_clean
241. self.cleaned_data = self.clean()
File "C:\PYTHON25\Lib\site-packages\django\forms\models.py" in clean
223. self.validate_unique()
File "C:\PYTHON25\Lib\site-packages\django\forms\models.py" in
validate_unique
251. if f.unique and self.cleaned_data.get(name) is not
Exception Type: AttributeError at /ftrTool/searchFeature/
Exception Value: 'RelatedObject' object has no attribute 'unique'
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---