How to serialize django model using serpy?
See original GitHub issueKinda new to python and django so I apologize if this is a noobish question. How would I serialize this following related models using Serpy instead of DRF ModelSerializer and then use the serpy serializer in a DRF ModelViewSet?
Models:
class Person(models.Model):
first_name = models.CharField(_("First Name"), max_length=128, null=True)
middle_name = models.CharField(_("Middle Name"), max_length=128, blank=True, null=True)
last_name = models.CharField(_("Last Name"), max_length=128, null=True)
email = models.EmailField(_("Email"), blank=True, null=True)
def __unicode__ (self):
return '%s: %s %s %s' % (self.id, self.first_name, self.middle_name, self.last_name)
class Bookmark(models.Model):
person = models.ForeignKey(Person, related_name='bookmarks', on_delete=models.CASCADE)
title = models.CharField(_("Title"), max_length=9999, blank=True, null=True)
url = models.URLField(_("Url"), max_length=9999, blank=True, null=True)
def __unicode__ (self):
return '%s %s' % (self.title, self.url)
DRF ModelSerializers:
class BookmarkSerializer(ModelSerializer):
class Meta:
model = Bookmark
fields = ('id', 'title', 'url', 'person')
class PersonSerializer(ModelSerializer):
bookmarks = BookmarkSerializer(many=True, read_only=True)
class Meta:
model = Person
fields = ('id', 'first_name', 'middle_name', 'last_name', 'email', 'bookmarks')
DRF ModelViewSet:
class PersonViewSet(viewsets.ModelViewSet):
queryset = Person.objects.all()
serializer_class = PersonSerializer
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
serpy: ridiculously fast object serialization — serpy 0.3.1 ...
serpy is a super simple object serialization framework built for speed. serpy serializes complex datatypes (Django Models, custom classes, …) ...
Read more >How to serialize a django model using serpy package
I'm trying to serialize the default User model using the serpy package but no success. Serializers class GroupSerializer(serpy.
Read more >drf-serpy - PyPI
drf-serpy is a super simple object serialization framework built for speed. drf-serpy serializes complex datatypes (Django Models, ...
Read more >Tutorial 1: Serialization - Django REST framework
We can do this by declaring serializers that work very similar to Django's forms. Create a file in the snippets directory named serializers.py...
Read more >JSON Serialization in Python using serpy - Twilio
The simplest thing to do here would be to separate the serializer definition from the original class definition. This is where serpy comes...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah. Try:
Set required=False