Sorry Mark,

But I am going to add to your problem since I encountered something
this weekend that was similar. If I add a Waiter class to this example:

class Waiter(meta.Model):
    name = meta.CharField(maxlength=50)
    restaurant = meta.ForeignKey(Restaurant)

    def __repr__(self):
        return "%s waits at %s" % (self.name, self.get_restaurant())

But, I have a multitude of problems that I don't believe I had before
the recent model overhaul. Here are some example things I tried doing
with my Waiter class that I believe should work:

from django.models.places import places, restaurants, waiters

# Works Fine
p = places.Place(name='Demon Dogs', address='944 W. Fullerton')
p.save()

# Works Fine
r = restaurants.Restaurant(place=p, serves_hot_dogs=True,
serves_pizza=False)
r.save()

# This Fails:
w = r.add_waiter(name="John Doe")
#    Traceback (most recent call last):
#      File "test_places.py", line 13, in ?
#        w = r.add_waiter(name="John Doe")
#      File "C:\www\django\utils\functional.py", line 3, in _curried
#        return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
#      File "C:\www\django\core\meta\__init__.py", line 944, in
method_add_related
#        obj = rel_mod.Klass(**init_kwargs)
#      File "C:\www\django\utils\functional.py", line 3, in _curried
#        return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
#      File "C:\www\django\core\meta\__init__.py", line 755, in
method_init
#        raise TypeError, "Invalid value: %r should be a %s instance,
not a %s" % (f.name, f.rel.to, type(rel_obj))
#    TypeError: Invalid value: 'restaurant' should be a <Options for
restaurants> instance, not a <class 'django.models.places.Restaurant'>

# So Does This:
w = waiters.Waiter(restaurant=r, name="John Doe")
#    Traceback (most recent call last):
#      File "test_places.py", line 27, in ?
#        w = waiters.Waiter(restaurant=r, name="John Doe")
#      File "C:\www\django\utils\functional.py", line 3, in _curried
#        return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
#      File "C:\www\django\core\meta\__init__.py", line 755, in
method_init
#        raise TypeError, "Invalid value: %r should be a %s instance,
not a %s" % (f.name, f.rel.to, type(rel_obj))
#    TypeError: Invalid value: 'restaurant' should be a <Options for
restaurants> instance, not a <class 'django.models.places.Restaurant'>

# This Hack Works
w = waiters.Waiter(restaurant_id=r.place_id, name="John Doe")
w.save()

# But Even with a Correct Data Structure this Fails
print w.get_restaurant()
#    Traceback (most recent call last):
#      File "test_places.py", line 43, in ?
#        print w.get_restaurant()
#      File "C:\www\django\utils\functional.py", line 3, in _curried
#        return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
#      File "C:\www\django\core\meta\__init__.py", line 873, in
method_get_many_to_one
#        retrieved_obj = mod.get_object(**{'%s__exact' %
field_with_rel.rel.field_name: val})
#      File "C:\www\django\utils\functional.py", line 3, in _curried
#        return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))
#      File "C:\www\django\core\meta\__init__.py", line 1083, in
function_get_object
#        obj_list = function_get_list(opts, klass, **kwargs)
#      File "C:\www\django\core\meta\__init__.py", line 1123, in
function_get_list
#        return list(function_get_iterator(opts, klass, **kwargs))
#      File "C:\www\django\core\meta\__init__.py", line 1105, in
function_get_iterator
#        select, sql, params = function_get_sql_clause(opts, **kwargs)
#      File "C:\www\django\core\meta\__init__.py", line 1302, in
function_get_sql_clause
#        tables2, join_where2, where2, params2, _ =
_parse_lookup(kwargs.items(), opts)
#      File "C:\www\django\core\meta\__init__.py", line 1231, in
_parse_lookup
#        _throw_bad_kwarg_error(kwarg)
#      File "C:\www\django\core\meta\__init__.py", line 1181, in
_throw_bad_kwarg_error
#        raise TypeError, "got unexpected keyword argument '%s'" %
kwarg
#    TypeError: got unexpected keyword argument 'place__exact'

Originally, I was going to ditch the use of OneToOne because I thought
I was simply using it incorrectly in my design... but after seeing
Mark's post and whipping up this example, I believe there is a bug.

I also hope my post clarifies not confuses Mark's post... because I
believe they are related issues.

regards,
-ian

Reply via email to