> 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
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
> 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
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
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
5 matches
Mail list logo