Using Related field under different name
See original GitHub issueI want to use Related
field for many to many relations in my schemas but under different name than real property name, but there is problems on serialization step even if using attribute
argument pointing to wanted property because Marshmallow trying to access same property but pick it from related model.
Any guides how to use Related
field under different name than property name?
Pseudocode example:
class Article(Base):
id = Column(UUID,
server_default=text('gen_random_uuid()'),
primary_key=True)
name = Column(String(256))
pictures = relationship('File', secondary=article_to_picture)
class ArticleSchema(ModelSchema):
class Meta:
model = Article
pictures_ids = fields.List(Relation(attribute='pictures'), attribute='pictures'))
pictures = fields.Nested('FileSchema',
attribute='pictures',
many=True,
only=['id', 'name', 'url'],
dump_only=True)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Querying using related field names - django - Stack Overflow
I'm wondering how to do this given the fact that one model has to fields with foreign keys to the same model. class...
Read more >Similar field name on different objects : not easy when used in ...
We have some fields duplicated on different objects (used in workflow & field updates & email alerts). This is all working fine.
Read more >Guidelines for naming fields, controls, and objects
When you name a field, control, or object, it's a good idea to make sure the name doesn't duplicate the name of a...
Read more >Define fields in tables—ArcGIS Pro | Documentation
Field names in the same table must be unique; for instance, you can't have two fields with the name ObjectID.
Read more >Editing field names and descriptions - Amazon QuickSight
You can change any field name and description from what is provided by the data source. If you change the name of a...
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
@AbdealiJK Ah, ok. As long as you have
dump_only=True
orload_only=True
set on either of the fields, then you will not run into any issues.Thank you, @sloria and @AbdealiJK! It was long time ago, I will review my code soon.