Thejaswi, > Problem: > The check constraints got added successfully (after a syncdb) but the > problem is when I go to the admin page and to the model's page in it, > I get an error ... This error vanishes when I comment the check fields > in the models.py. I don't understand why the Check (pseudo) field is > getting (trying to get) rendered in the Admin section.
I think what's going on here is that since you decided to implement your constraint checks as a field, django tries to retrieve the check field on queries. Specifically, take a look at line 477 in _get_sql_clause() from django/db/models/query.py: http://code.djangoproject.com/browser/django/trunk/django/db/models/query.py#L477 The select statement is being constructed for every field in the the model, as it does by default. However, when the query is run the database cannot find that column and throws an error. The model thinks check is a valid field because it is within the _meta.fields attribute of the model. The check field gets added to the _meta.fields model attribute when the contribute_to_class() method (inherited from the Field base class) is called: http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/__init__.py#L142 You could override the contribute_to_class() method in your Check class definition to prevent this from happening, but then the SQL would not be executed from management.py (since it increments over _meta.fields). I'm at a loss for a solution right now, but I think that's your problem. One idea is to place the check field in different attribute in _meta (see django/db/models/options.py). Regards, -Justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@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-developers?hl=en -~----------~----~----~----~------~----~------~--~---