FAQ
Hallo,

I have a problem running Django's full_validation-method upon an
instance of an inherited model. Please consider the following two models:

class ParentModel(models.Model):

parent_model_id = models.IntegerField(primary_key=True)
parent_model_attr = models.CharField(max_length=200)


class ChildModel(ParentModel):

child_model_attr = models.CharField(max_length=200)

Creating a ChildModel by using the keyword pk instead of the primary
key's real attribute name and running full_validation on it before
saving (after saving this method does not make much sense, I think)
leads to an error as shown below:
from mytest.models import ChildModel
cm = ChildModel(pk=1,child_model_attr='some
text',parent_model_attr='Some other text')
cm.full_clean()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/django/db/models/base.py",
line 824, in full_clean
raise ValidationError(errors)
ValidationError: {'parent_model_id': [u'This field cannot be null.']}


Using the primary key's real attribute name works of course (but cannot
be done in my scenario).

Any ideas how to make using the pk-keyword work without that validation
error?

Thanks in advance for any hint.


With best regards

Carsten Reimer


--
Carsten Reimer
Web Developer
carsten.reimer@galileo-press.de
Phone +49.228.42150.73

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Phone +49.228.42150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Managing Directors: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn

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

Search Discussions

  • Carsten Reimer at Jun 18, 2012 at 9:07 am
    in my previous post I named the method in question full_validation. This
    is obviously wrong. It must be full_clean. Sorry for that.

    Carsten Reimer schrieb:
    Hallo,

    I have a problem running Django's full_validation-method upon an
    instance of an inherited model. Please consider the following two models:

    class ParentModel(models.Model):

    parent_model_id = models.IntegerField(primary_key=True)
    parent_model_attr = models.CharField(max_length=200)


    class ChildModel(ParentModel):

    child_model_attr = models.CharField(max_length=200)

    Creating a ChildModel by using the keyword pk instead of the primary
    key's real attribute name and running full_validation on it before
    saving (after saving this method does not make much sense, I think)
    leads to an error as shown below:
    from mytest.models import ChildModel
    cm = ChildModel(pk=1,child_model_attr='some
    text',parent_model_attr='Some other text')
    cm.full_clean()
    Traceback (most recent call last):
    File "<console>", line 1, in <module>
    File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line
    824, in full_clean
    raise ValidationError(errors)
    ValidationError: {'parent_model_id': [u'This field cannot be null.']}


    Using the primary key's real attribute name works of course (but cannot
    be done in my scenario).

    Any ideas how to make using the pk-keyword work without that validation
    error?

    Thanks in advance for any hint.


    With best regards

    Carsten Reimer

    --
    Carsten Reimer
    Web Developer
    carsten.reimer@galileo-press.de
    Phone +49.228.42150.73

    Galileo Press GmbH
    Rheinwerkallee 4 - 53227 Bonn - Germany
    Phone +49.228.42150.0 (Zentrale) .77 (Fax)
    http://www.galileo-press.de/

    Managing Directors: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
    HRB 8363 Amtsgericht Bonn

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedJun 18, '12 at 8:46a
activeJun 18, '12 at 9:07a
posts2
users1
websitedjangoproject.com

1 user in discussion

Carsten Reimer: 2 posts

People

Translate

site design / logo © 2022 Grokbase