Multiple objects returned while serializing using cities__name_std
See original GitHub issueI have serializer like this: `class ExperienceSerializer(serializers.ModelSerializer):
experience_type = ChoicesField(choices=Experience.EXPERIENCE_TYPE)
location = serializers.SlugRelatedField(slug_field='name_std', queryset=City.objects.all())
`
Whenever I enter “Delhi” as location It fails with “get() returned more than one City – it returned 2!” There are cities with same name so how to hanle this scenario?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Multiple Objects Returned - django - Stack Overflow
I want a all subject data according to course which I select..When I hit this api if single data present working awesome but...
Read more >7780 (get returns multiple objects when model includes a ...
Django throws a MultipleObjectsReturned error when getting a single instance of a model that includes a ManyToManyField in the default ordering.
Read more >Django Rest Framework API #22 / Many To Many ... - YouTube
Django Rest Framework API Model RelationshipsHow to implement ManyToMany Relationship to link multiple objects of one model with multiple ...
Read more >Custom object creation - Optimizely
This topic describes how to customize instantiation of objects returned in search results in Optimizely Search & Navigation.
Read more >returned correct array with multiple objects, but - Esri Community
Hello All, I have a simple method to get portal users by a role and put them in an array and return the...
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 Free
Top 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
I just pushed version 0.5 to PyPI, so you should be able to upgrade using pip:
That version adds slugs to models, and allows you to specify your own
slugify()
function for all django-cities objects if you don’t want to use the default slugify function I wrote.Since all of the building blocks are in place, and the default settings should handle this (or at least handle 90% of it), I’m closing this issue. Feel free to reopen it if you run into any issues. Cheers!
You will need to use the slug field for this - that’s what it’s there for after all!
Keep in mind that you will need to fill in that field yourself, but…
I’ve got some changes I need to push, and one of them is creating a unique constraint on the
Place
(abstract) model’s slug field and giving each model aslugify()
method. That should allow you to use the slug field to uniquely identify each city. I’ll try to get that pushed either later today or Friday for you.