class MyModel(models.Model):
....
CONST = MyModel.objects.get(id=1)
The problem is, that during class definition <module>_mymodel table
might not exist or there might not be those objects there.
Of course I could do it like this:
class MyModel(models.Model):
@classmethod
def CONST1(Class):
return Class.objects.get(id=1)
but I don't like it, because I would have to call a constant, rather
than just access it and it is against our coding conventions. I though
about having a metaclass, that would add __getattr__ to MyModel, that
would be used during run time, but Model subclasses can't have own
metaclass.
So, is there any other way?
What I am thinking, is attaching those constants after table are
created _and_ fixtures are loaded. Is there any hook in django, that I
could use?
--
Filip Gruszczyński
--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment