I'm not sure if it is possible, but I'm trying to add a model manager
defined outside of the model.py to a modelclass, in a similar way as I
add functions to a model class.
this is how I add a new function to a model class (leaving out
## in models.py
class Customer(models.Model):
customer_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
companyname = models.CharField(max_length=255)
active = models.BooleanField()
## in modeldefs.py
def unicode_name(self):
return ("%s [%s]" %(self.name, self.companyname)
## in __init__.py
from cust.modeldefs import unicode_name
setattr(Customer, '__unicode__', unicode_name)
So far so good.
Now I want to add a customanager.
I can define the manager as follows (directly adapted from the
manual) inside models.py:
class CustomerManager(models.Manager):
def get_query_set(self):
return super(CustomerManager,
self).get_query_set().filter(active=True)
class Customer(models.Model):
customer_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
companyname = models.CharField(max_length=255)
active = models.BooleanField()
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.