35👍
✅
You should be able to define it as a field try:
class UserProfileResource(ModelResource):
fullname = fields.CharField(attribute='_get_full_name', readonly=True)
class Meta:
queryset = models.UserProfile.objects.all()
authorization = DjangoAuthorization()
fields = ['gender',]
Edit
You also have to include: set readonly=True
on your CharField
, or TastyPie will try to set its value on insertion or update.
3👍
A full example with dehydrate:
class UserResource(ModelResource):
fullname = fields.CharField(readonly=True)
class Meta:
queryset = auth_models.User.objects.all()
resource_name = 'user'
def dehydrate_fullname(self, bundle):
return u"{first_name} {last_name}".format(
first_name=bundle.obj.first_name, last_name=bundle.obj.last_name)
👤dzen
- [Django]-How to validate a field on update in DRF?
- [Django]-How do I write Facebook apps using Django?
- [Django]-Django edit user profile
Source:stackexchange.com