Opened 22 months ago

Closed 22 months ago

Last modified 22 months ago

#34308 closed New feature (wontfix)

Create Serializers for models

Reported by: Hemed Tov Owned by: Hemed Tov
Component: Core (Serialization) Version: dev
Severity: Normal Keywords: Serializer, Model
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

  • Provide CLI to generate corresponding serializers for existing models
  • The serializers will be in a seperate module named model_serializers.py, and the serializers module will import from that.
  • The default serializer for each model will include as fields all db column names.
  • The serializer default name will be the name of the model and serializer

Example:

class Coffee(models.Model):
   type = models.Charfield(db_column='type')
   roast_degree = models.IntegerFIeld(db_column='roast_degree)
   temperature = models.IntegerFIeld(db_column='temperature')
  
   class Meta:
     db_table = 'coffee'

After running the function:

class CoffeeSerializer(serializers.ModelSerializer):
    class Meta:
          model = Coffee
          fields = [
                   'type',
                   'roast_degree',
                   'temperature',
                    ]

Change History (2)

comment:1 by Mariusz Felisiak, 22 months ago

Resolution: wontfix
Status: assignedclosed
Summary: Feature request: Create Serializers for modelsCreate Serializers for models

Hi, thanks for the proposition, however I'm not sure what kind of serialization you expect from ModelSerializer if it's similar to what django-rest-framework does then it's a duplicate of #32362. I will treat this report as a request for a new management command. I don't see this as something Django needs to provide and ModelSerializer is not a part of Django.

comment:2 by Hemed Tov, 22 months ago

OK thanks. Sorry, I missed that duplicate issue in my search.

Note: See TracTickets for help on using tickets.
Back to Top