#18389: Field type attributes not permitted on models ----------------------------------------------+-------------------- Reporter: john.arnfield@… | Owner: nobody Type: Uncategorized | Status: new Component: Database layer (models, ORM) | Version: 1.4 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- I have a situation where I need to reference a django model-field type in my models, something that would look like the following:
{{{ from django.db import models class MyModel(models.Model): referenced_field = models.CharField # ... field declarations here }}} The omission of parenthesis on the CharField is intentional. I do not want to create a field on this model, I simply need to reference a field type that this model is associated with. Unfortunately this causes a type error: {{{ TypeError: Error when calling the metaclass bases unbound method contribute_to_class() must be called with AutoField instance as first argument (got ModelBase instance instead) }}} This is down to ModelBase.add_to_class being overly naive in the way it calls contribute_to_class (it uses hasattr to check for things that define contribute_to_class, but doesn't care if they're types or objects). One solution to this problem would be to change the class attribute in to a classmethod, but the problem seems a little unnecessary and feels like it should be cleaned up regardless. Unfortunately, I'm not sure what the ideal solution would be for this case, else I'd already have submit a patch. -- Ticket URL: <https://code.djangoproject.com/ticket/18389> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.