Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#11829 closed (invalid)

django-admin model validation mistake

Reported by: Nick Meharry Owned by: nobody
Component: Core (Management commands) Version: 1.0
Severity: Keywords: model db_column
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In one of my models I have a field that would be logically be called class, but because it is a reserved word, I renamed the field to class_ (notice the trailing underscore). I also set the db_column kwarg to class. I then run ./manage.py sql tracker, and get this error:

    Error: One or more models did not validate:
    tracker.assignment: "class_": Field names cannot end with underscores, because this would lead to ambiguous queryset filters.

However, when I set the model name to klass, the output shows it recognizes the db_column setting. It seems that the validator should check for that setting before emitting an error. Is there a work around I should use for now? I'd rather not spell "class" with a "k".

System Info:

  • Ubuntu 9.04
  • Django 1.0.2

-- Nick

Change History (2)

comment:1 by James Bennett, 15 years ago

Resolution: invalid
Status: newclosed

Field names ending with underscores are invalid regardless of db_column, because the Python-level query API separates field names/joins/lookup types with underscores; as the error message tells you, ending a field name in an underscore would lead to ambiguity in parsing the Python-level field lookups.

comment:2 by Nick Meharry, 15 years ago

I feel like an idiot now for not realizing that. I suppose that's what I get for filing a bug report late at night.

Note: See TracTickets for help on using tickets.
Back to Top