Hi guys!

I'm having troubles using admin interface to add an inline object that
have a unique constraint in it. Look the code:

class Office(Model):

    name = CharField(maxlength=200)

    def website(self):
        return self.office_set.all()[0]

    def __str__(self):
        return self.name

    class Admin:
        pass

class WebSite(Model):

    office = ForeignKey(Office, edit_inline=STACKED, num_in_admin=1,
max_num_in_admin=1)
    host_name = CharField(maxlength=64, unique=True, core=True)

    def __str__(self):
        return self.host_name


I didn't use the OneToOneField in this case because I can't edit the
objects on the admin interface (I can add it, but can't edit). Anyway,
OneToOneField will be rewritten :D, so no problem. The problem here is
that if I use the unique constraint in the host_name, I can't add or
edit any object on the admin interface, if I remove these unique
constraint, I can use the admin without any problem.

I get an exception: TypeError, cannot resolve keyword 'host_name' into
field, look the complete traceback:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
core/handlers/base.py" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
contrib/admin/views/decorators.py" in _checklogin
  55. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
views/decorators/cache.py" in _wrapped_view_func
  39. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
contrib/admin/views/main.py" in add_stage
  250. errors = manipulator.get_validation_errors(new_data)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
forms/__init__.py" in get_validation_errors
  58. errors.update(field.get_validation_errors(new_data))
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
forms/__init__.py" in get_validation_errors
  351. self.run_validator(new_data, validator)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/
forms/__init__.py" in run_validator
  341. validator(new_data.get(self.field_name, ''), new_data)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/fields/__init__.py" in manipulator_validator_unique
  35. old_obj = self.manager.get(**{lookup_type: field_data})
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/manager.py" in get
  67. return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in get
  211. obj_list = list(clone)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in __iter__
  103. return iter(self._get_data())
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in _get_data
  430. self._result_cache = list(self.iterator())
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in iterator
  171. select, sql, params = self._get_sql_clause()
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in _get_sql_clause
  444. joins2, where2, params2 = self._filters.get_sql(opts)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in get_sql
  574. joins2, where2, params2 = val.get_sql(opts)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in get_sql
  622. return parse_lookup(self.kwargs.items(), opts)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in parse_lookup
  734. joins2, where2, params2 = lookup_inner(path, lookup_type,
value, opts, opts.db_table, None)
File "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/
models/query.py" in lookup_inner
  835. raise TypeError, "Cannot resolve keyword '%s' into field" %
name

  TypeError at /admin/portal/office/add/
  Cannot resolve keyword 'host_name' into field

...

Not a real problem for me now, I can live with this, I'm not very
familiar with django code, but it seems it will be waste of time to
fix this bug as the validation will be rewritten to be conform
newforms. But anyway I'd to tell you about this bug ;)

Best regards,

Michel


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to