python - Django model property without a field -


is possible set property in django (for backwards compatibility), without corresponding field? here simple test case custom user model:

class customuser(abstractbaseuser):   email = models.emailfield(max_length=254, unique=true, db_index=true)   username_field = 'email'   ...   permissions = models.integerfield(default=0)    @property   def is_staff(self):     return self.permissions >= 2   @is_staff.setter   def is_staff(self, value):     if value , not self.is_staff:       self.permissions = 2     if not value , self.is_staff:       self.permissions = 1 

now when try load user using default admin interface, following error: 'customuseradmin.list_filter[0]' refers 'is_staff' not refer field.

is there way set model provides is_staff function of field?

it's possible, , code you've given not cause problems. problem comes because you've tried use property in admin list_filter, can't do, because filtering translates db query, needs actual db field.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -