Custom model fields not working?

91 views
Skip to first unread message

oli...@obeattie.com

unread,
Dec 11, 2007, 3:42:54 PM12/11/07
to Django users
Hey everyone,

I've asked a little in the Django IRC, but nobody seems to be able to
help. I'm trying to implement a custom model field, and I really can't
figure out why I keep getting errors. My code for my fields module is
at http://dpaste.com/hold/27712/

When I try to run syncdb on a model which uses the PickledObjectField
(see my sample model at http://dpaste.com/hold/27713/), I get this
traceback:-

Macintosh:sandbox Oliver$ cd /Django/sandbox && python manage.py
syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Django Source/django/core/management/__init__.py", line 272,
in execute_manager
utility.execute()
File "/Django Source/django/core/management/__init__.py", line 219,
in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Django Source/django/core/management/base.py", line 70, in
run_from_argv
self.execute(*args, **options.__dict__)
File "/Django Source/django/core/management/base.py", line 83, in
execute
self.validate()
File "/Django Source/django/core/management/base.py", line 110, in
validate
num_errors = get_validation_errors(s, app)
File "/Django Source/django/core/management/validation.py", line 28,
in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Django Source/django/db/models/loading.py", line 126, in
get_app_errors
self._populate()
File "/Django Source/django/db/models/loading.py", line 55, in
_populate
self.load_app(app_name, True)
File "/Django Source/django/db/models/loading.py", line 70, in
load_app
mod = __import__(app_name, {}, {}, ['models'])
File "/Django/sandbox/../sandbox/geo/models.py", line 247, in
<module>
class TestModel(models.Model):
File "/Django Source/django/db/models/base.py", line 62, in __new__
new_class.add_to_class(obj_name, obj)
File "/Django Source/django/db/models/base.py", line 184, in
add_to_class
value.contribute_to_class(cls, name)
TypeError: Error when calling the metaclass bases
unbound method contribute_to_class() must be called with
PickledObjectField instance as first argument (got ModelBase instance
instead)
Macintosh:sandbox Oliver$

Can anyone point me in the right direction?

Thanks so much,
Oliver

Marty Alchin

unread,
Dec 11, 2007, 4:04:50 PM12/11/07
to django...@googlegroups.com
On Dec 11, 2007 3:42 PM, oli...@obeattie.com <oli...@obeattie.com> wrote:
> When I try to run syncdb on a model which uses the PickledObjectField
> (see my sample model at http://dpaste.com/hold/27713/), I get this
> traceback:-

Your problem is that you're importing the PickledObjectField into your
class's namespace. So when Django processes your form definition, it's
actually getting two attributes:

* lookups (instantiated, which will work fine)
* PickledObjectField (uninstantiated, which will cause errors)

Move the import statement to the top of your models.py file, where it
belongs, and you should find that the error goes away.

There are no doubt other things you'll run into, but I'll at least
give you a chance to work them out on your own. :)

-Gul

oli...@obeattie.com

unread,
Dec 11, 2007, 4:06:19 PM12/11/07
to Django users
You're a saint, you know that?

On Dec 11, 9:04 pm, "Marty Alchin" <gulop...@gamemusic.org> wrote:
> On Dec 11, 2007 3:42 PM, oli...@obeattie.com <oli...@obeattie.com> wrote:
>
> > When I try to run syncdb on a model which uses the PickledObjectField
> > (see my sample model athttp://dpaste.com/hold/27713/), I get this

oli...@obeattie.com

unread,
Dec 11, 2007, 5:34:39 PM12/11/07
to Django users
OK, well now, for some reason whenever I use a custom field Django
just ignores it when running syncdb. If I ask it for the raw SQL
output I can see that the field is being omitted entirely. Even if I
do something simple like:

class TestField(models.TextField):
pass

Does anyone know what I am doing wrong?

On Dec 11, 9:04 pm, "Marty Alchin" <gulop...@gamemusic.org> wrote:
> On Dec 11, 2007 3:42 PM, oli...@obeattie.com <oli...@obeattie.com> wrote:
>
> > When I try to run syncdb on a model which uses the PickledObjectField
> > (see my sample model athttp://dpaste.com/hold/27713/), I get this

oli...@obeattie.com

unread,
Dec 11, 2007, 5:40:14 PM12/11/07
to Django users
Never mind, I see it's to do with database backends.

On Dec 11, 10:34 pm, "oli...@obeattie.com" <oli...@obeattie.com>
wrote:

joe.y...@gmail.com

unread,
Aug 5, 2013, 11:20:18 PM8/5/13
to django...@googlegroups.com, oli...@obeattie.com
Hey!
I'm dealing with a similar issue. 
Would you be able to tell me if you managed to solve this issue? 
and if so, how?

Thanks!
Joe

Oliver Beattie

unread,
Aug 6, 2013, 6:37:37 AM8/6/13
to joe.y...@gmail.com, django...@googlegroups.com
This was more than 5 years ago… wow!

Sorry, I have absolutely no idea now. I would suspect that "yes," I got it sorted, but I would anticipate that the internals of Django's ORM have changed significantly since then, so even if I could remember how I did it, it wouldn't be of much use…

Perhaps if you post with more detail of the exact issue you are experiencing someone can help you out.
Reply all
Reply to author
Forward
0 new messages