"model_name" object has no attribute '_adding'

64 views
Skip to first unread message

dizzydoc

unread,
Feb 27, 2012, 11:30:40 PM2/27/12
to Django users
Hi django users,

I have just migrated my projected from django 1.2.7 to django 1.3.

I am receiving the following error while saving an object from admin.

"model_name" object has no attribute '_adding'

I am getting this error in clean method of some of my models where i
use it the following way:

def clean( self ):
from django.core.exceptions import ValidationError
if self._adding: (do this)
else: (do this)

Please help if you have any clue, while i search for the fix.

Thanks.

Andres Reyes

unread,
Feb 28, 2012, 9:18:37 AM2/28/12
to django...@googlegroups.com
I don't remember reading anything about an "_adding" attribute in the
documentation. However, if you want to check for an INSERT vs an
UPDATE just check for the existence of a primary key

def clean( self ):
from django.core.exceptions import ValidationError

if self.pk is None: (do this)
else: (do this)

2012/2/27 dizzydoc <htc.kara...@gmail.com>:

> --
> 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.
>

--
Andrés Reyes Monge
arm...@gmail.com
+(505)-8873-7217

akaariai

unread,
Feb 28, 2012, 10:55:42 AM2/28/12
to Django users
The _adding variable was moved to ModelState. So, above should read:
if self._state.adding:

- Anssi

Andres Reyes

unread,
Feb 28, 2012, 4:39:01 PM2/28/12
to django...@googlegroups.com
I'm curious as to where is this in the documentation. I think this is
a private attribute so it shouldn't be depended upon

2012/2/28 akaariai <akaa...@gmail.com>:

akaariai

unread,
Feb 29, 2012, 2:08:31 AM2/29/12
to Django users
On Feb 28, 11:39 pm, Andres Reyes <armo...@gmail.com> wrote:
> I'm curious as to where is this in the documentation. I think this is
> a private attribute so it shouldn't be depended upon

It is a private attribute. So use it at your own risk. If it changes
underneath you, though luck.

- Anssi
Reply all
Reply to author
Forward
0 new messages