django-localized-fields | Implementation of localized model fields | Internationalization library
kandi X-RAY | django-localized-fields Summary
kandi X-RAY | django-localized-fields Summary
2.0, 2.1, 2.2, 3.0, 3.1. 3.6, 3.7, 3.8, 3.9. django-localized-fields is an implementation of a field class for Django models that allows the field's value to be set in multiple languages. It does this by utilizing the hstore type (PostgreSQL specific), which is available as models.HStoreField since Django 1.10. :warning: This README is for v6. See the v5.x branch for v5.x.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Validate and set the slug
- Returns a tuple of values and their values
- Resolve an object property
- Gets the value
- Set a language value
- Gets the value from the given field
- Prepare the value
- Validate that the value is not None
- Checks if value is empty
- Creates a slug
- Make a unique slug
- Converts the value to the corresponding value
- Convert a localized value to a LocalizedIntegerValue
- Convert the value to the native value
- Convert a local value to a LocalizedFloatValue
- Prepare the value of the attribute
- Prepare value for the column
- Prepare the value for saving
- Create a new custom command
- Return the locale of the current object
django-localized-fields Key Features
django-localized-fields Examples and Code Snippets
Community Discussions
Trending Discussions on django-localized-fields
QUESTION
I'm trying to avoid having duplicate localized items stored in a Django-rest-framework app, django-localalized-fields package with a PostgreSQL database I can't find any way to make this work.
(https://pypi.org/project/django-localized-fields/)
I've tried writing custom duplicate detection logic in the Serializer, which works for create, but for update the localized fields become null (they are required fields, so I receive a not null constraint error). It seems to be django-localized-fields utility which is causing this problem.
The serializer runs correctly (create/update) when I'm not overriding create/update in the serializer by defining them separately.
I've also tried adding unique options to the database in the model, which does not work - duplicates are still created. Using the standard unique methods, or the method in the django-localized-fields documentation (uniqueness=['en', 'ro']).
I've also tried the UniqueTogetherValidator in Django, which also doesn't seem to support HStore/localizedfields.
I'd appreciate some help in tracking down either how to fix the update in the serializer or place a unique constraint in the database. Since django-localized-fields uses hstore in PostgreSQL it must be a common enough problem for applications using hstore to maintain uniqueness.
For those who aren't familiar, Hstore stores items as key/value pairs within a database. Here's an example of how django-localized-fields stores language data within the database:
"en"=>"english word!", "es"=>"", "fr"=>"", "frqc"=>"", "fr-ca"=>""
...ANSWER
Answered 2020-Jan-14 at 13:54django-localized-fields constraint unique values only per the same language. If you want to achieve that values in a row don't collide with values in another row, you have to validate them on Django and database level.
Validation in DjangoIn Django you can create custom function validate_hstore_uniqueness
, which is called everytime is model validated.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-localized-fields
Clone the repository: λ git clone https://github.com/SectorLabs/django-localized-fields.git
Create a virtual environment: λ cd django-localized-fields λ virtualenv env λ source env/bin/activate
Create a postgres user for use in tests (skip if your default user is a postgres superuser): λ createuser --superuser psqlextra --pwprompt λ export DATABASE_URL=postgres://localized_fields:<password>@localhost/localized_fields Hint: if you're using virtualenvwrapper, you might find it beneficial to put the export line in $VIRTUAL_ENV/bin/postactivate so that it's always available when using this virtualenv.
Install the development/test dependencies: λ pip install ".[test]" ".[analysis]"
Run the tests: λ tox
Auto-format code, sort imports and auto-fix linting errors: λ python setup.py fix
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page