Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added section for Choice fields in documentation for types #146

Closed
wants to merge 2 commits into from

Conversation

ccsv
Copy link
Contributor

@ccsv ccsv commented Jul 17, 2022

Added Enums example for Integer choices

Description

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • [ x] Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

ccsv and others added 2 commits July 17, 2022 02:41
Comment on lines +37 to +41
@strawberry.enum
class FruitColor(Enum):
Red = 1
Yellow = 2
Green = 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since IntegerChoices is an enum itself, this can probably be simplified to:

Suggested change
@strawberry.enum
class FruitColor(Enum):
Red = 1
Yellow = 2
Green = 3
FruitColor = strawberry.enum(models.FruitColor, name="FruitColor")

Maybe mention the two cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to mention that the enum itself in the models.py module can be decorated and used directly by both django and strawberry


```python
# models.py
class FruitColor(models.IntegerChoices):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an example for TextChoices as well?

@bellini666
Copy link
Member

This has not have any activity for a while now so I'm closing this to clean up the backlog a little.

In case op or anyone wants to get back to this, feel free to reopen, or ask me to reopen in case you don't have permission to :)

@bellini666 bellini666 closed this Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants