【发布时间】:2013-11-29 10:46:41
【问题描述】:
使用 TastyPie 的 obj_create 方法我想覆盖包保存并调用我的模型对象管理器方法create_member() 但尝试这样做时出现以下错误:
Manager isn't accessible via MemberParticipant instances
如何在 TastyPie 中访问我的对象管理器方法? bundle.obj 似乎没有访问权限!
试过了:
def obj_create(self, bundle, request=None, **kwargs):
bundle.obj = self._meta.object_class()
bundle.obj.objects.create_member(stuff)
return bundle
型号:
class MemberManager(models.Manager):
def create_member(self, email, password=None, **extra_fields):
"""
Creates and saves new Member Participant with the given email, password and account.
"""
time_now = timezone.now()
stuff here
class MemberParticipant(AbstractParticipant):
email = models.CharField(max_length=50, blank=True)
objects = MemberManager()
class Meta:
app_label = 'participants'
【问题讨论】: