hi,

I have a modelForm for a model where one field is excluded. One of the lines in 
my model validation needs that field - so model validation fails with a 
'DoesNotExist' error. How does one get round this? The relevant parts of the 
model and the traceback are appended. The field excluded is 'player'.

model:

class Handicap(models.Model):
    """just name and handicap index - how to handle validity?"""
    player = models.ForeignKey(Player,verbose_name=_("Player"))
    handicap = models.DecimalField(_("Handicap index"),max_digits=3, 
decimal_places=1)
    valfrom = models.DateField(_("Valid from"))
    valto = models.DateField(_("Valid to"))
    class Meta:
        unique_together = ('player','valto')

    def clean(self):

        if self.valfrom >= self.valto:
            raise ValidationError(_("from date should be less than to date"))
        for hand in self.player.handicap_set.all():
            if self.valto == hand.valto:
                raise ValidationError(_("There is another handicap with the 
same to date"))

traceback:

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/addhandicap/1/
Django Version: 1.2 beta 1 SVN-12403
Python Version: 2.6.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'djangogolf.web']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.6/django/core/handlers/base.py" in get_response
  101.                     response = callback(request, *callback_args, 
**callback_kwargs)
File "/usr/lib/python2.6/django/contrib/auth/decorators.py" in _wrapped_view
  24.                 return view_func(request, *args, **kwargs)
File "/home/lawgon/djangogolf/../djangogolf/web/views.py" in addhandicap
  628.         if form.is_valid():
File "/usr/lib/python2.6/django/forms/forms.py" in is_valid
  120.         return self.is_bound and not bool(self.errors)
File "/usr/lib/python2.6/django/forms/forms.py" in _get_errors
  111.             self.full_clean()
File "/usr/lib/python2.6/django/forms/forms.py" in full_clean
  267.         self._clean_form()
File "/usr/lib/python2.6/django/forms/models.py" in _clean_form
  318.             self.instance.clean()
File "/home/lawgon/djangogolf/../djangogolf/web/models.py" in clean
  163.         for hand in self.player.handicap_set.all():
File "/usr/lib/python2.6/django/db/models/fields/related.py" in __get__
  264.                 raise self.field.rel.to.DoesNotExist

Exception Type: DoesNotExist at /addhandicap/1/
Exception Value: 
-- 
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to