Django models and Python properties -


i've tried set django model python property, so:

class post(models.model):     _summary = models.textfield(blank=true)     body = models.textfield()      @property     def summary(self):         if self._summary:             return self._summary         else:             return self.body      @summary.setter     def summary(self, value):         self._summary = value      @summary.deleter     def summary(self):         self._summary = '' 

so far good, , in console can interact summary property fine. when try django-y this, post(title="foo", summary="bar"), throws fit. there way django play nice python properties?

unfortunately, django models don't play nice python properties. way works, orm recognizes names of field instances in queryset filters.

you won't able refer summary in filters, instead you'll have use _summary. gets messy real quick, example refer field in multi-table query, you'd have use like

user.objects.filter(post___summary__contains="some string") 

see https://code.djangoproject.com/ticket/3148 more detail on property support.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -