Skip to content

Singe CRUD / request->response Operation two serializers #9630

Discussion options

You must be logged in to vote

I had this problem a few times and there are a few ways to solve the problem, depending on how much your request schema differs from your response schema. Generally speaking, I think it's a good idea to minimise the differences. I'll describe a few options I've adopted over time.

Example

Let's use a simple BlogPost model in an blogging application:

class BlogPost(models.Model):
    author = models.ForeignKey("auth.User", on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    body = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)

When a post of created, the author provides the title and body, and the other fields as derived from the request. …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jon-nfc
Comment options

@browniebroke
Comment options

@jon-nfc
Comment options

Answer selected by jon-nfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants