2014-05-08 16:59:35 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from .models import Account
|
|
|
|
|
|
|
|
|
|
|
|
class AccountSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Account
|
|
|
|
fields = (
|
2014-09-30 16:39:47 +00:00
|
|
|
'url', 'username', 'type', 'language', 'date_joined', 'is_active'
|
2014-05-08 16:59:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class AccountSerializerMixin(object):
|
2014-10-16 15:11:52 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(AccountSerializerMixin, self).__init__(*args, **kwargs)
|
|
|
|
self.account = None
|
|
|
|
request = self.context.get('request')
|
|
|
|
if request:
|
|
|
|
self.account = request.user
|
|
|
|
|
2014-05-08 16:59:35 +00:00
|
|
|
def save_object(self, obj, **kwargs):
|
2014-10-16 15:11:52 +00:00
|
|
|
obj.account = self.account
|
2014-05-08 16:59:35 +00:00
|
|
|
super(AccountSerializerMixin, self).save_object(obj, **kwargs)
|