Re: Constants in model, that point to certain objects in database

2011-01-25 Thread Filip Gruszczyński
> The descriptor protocol is the mechanism that allows both property and > method: > http://docs.python.org/reference/datamodel.html#implementing-descriptors > http://users.rcn.com/python/download/Descriptor.htm > > In your case, something like the following could do: This looks awesome. I had no

Re: Constants in model, that point to certain objects in database

2011-01-25 Thread bruno desthuilliers
On 24 jan, 21:20, Filip Gruszczyński wrote: > > > You could write a custom descriptor then. But the whole idea of a > > class-level pseudo-constant pointing to a model instance still looks > > rather backward to me. > > What is a custom descriptor? I have never used it. Is it something > like a pr

Re: Constants in model, that point to certain objects in database

2011-01-24 Thread Filip Gruszczyński
> FWIW, by that time, the MyModel class doesn't even exists yet - you > can't refer to the current class object inside a 'class' statement > body. Yes, you are right. What I meant was: class MyModel(models.Model): ... MyModel.CONST = MyModel.objects.get(id=1) > You could write a custom des

Re: Constants in model, that point to certain objects in database

2011-01-24 Thread bruno desthuilliers
On 24 jan, 16:43, Filip Gruszczyński wrote: > I would like to achieve something like this: > > class MyModel(models.Model): >       > >     CONST = MyModel.objects.get(id=1) > > The problem is, that during class definition _mymodel table > might not exist or there might not be those objects

Constants in model, that point to certain objects in database

2011-01-24 Thread Filip Gruszczyński
I would like to achieve something like this: class MyModel(models.Model): CONST = MyModel.objects.get(id=1) The problem is, that during class definition _mymodel table might not exist or there might not be those objects there. Of course I could do it like this: class MyModel(mode