You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add flexibility to use either BigInt or UUID for translation table primary key
- Introduced global and model-specific configuration for Lisan model primary keys
- Allowed choice of BigInt or UUID primary key, configurable via settings or per model
- Updated LisanModelMeta to dynamically apply primary key type to the translation model
Copy file name to clipboardexpand all lines: CHANGELOG.md
+67
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,70 @@
1
+
## [v0.1.5] - 2024-11-11
2
+
3
+
This release introduces two major enhancements to `Lisan`'s translation model functionality, improving flexibility in primary key configurations and structuring translation data for API responses.
4
+
5
+
### Added
6
+
-**Flexible Primary Key Configuration for Translation Tables**:
7
+
- Added support to configure primary key type for translation (Lisan) tables, allowing the use of either `BigInt` or `UUID` as primary keys.
8
+
- Configurable globally via `settings.py` (`LISAN_PRIMARY_KEY_TYPE`) or per model by setting the `lisan_primary_key_type` attribute.
9
+
- Ensures flexibility for projects that require UUIDs or BigInts based on specific requirements or database configurations.
10
+
11
+
-**Nested Translation Serializer for Structured API Responses**:
12
+
- Introduced a `TranslationSerializer` to handle multilingual data in API responses, providing a structured, nested format.
13
+
- Integrated `TranslationSerializer` within `LisanSerializerMixin`, enabling organized representation of translations in API responses.
14
+
- Allows each translation entry to include fields such as `language_code` and all specified translatable fields, making it easier to work with multilingual data in client applications.
15
+
16
+
### Improved
17
+
-**Dynamic Primary Key Assignment for Lisan Models**:
18
+
- Enhanced the `LisanModelMeta` metaclass to detect and apply the specified primary key type dynamically, either at the model level or globally.
19
+
- Ensured that the primary key type for Many-to-Many join tables remains `AutoField` even when the `Lisan` model uses `UUIDField` as its primary key, simplifying compatibility with Django’s default join tables.
20
+
21
+
### Configuration Changes
22
+
-**New Settings**:
23
+
-`LISAN_PRIMARY_KEY_TYPE`: Allows configuration of the primary key type for translation tables globally. Options include `BigAutoField` (default) and `UUIDField`.
24
+
25
+
### Migration Notes
26
+
- A new migration is required if you change the primary key type for existing translation tables. After updating, use the following commands:
27
+
28
+
```bash
29
+
python manage.py makemigrations
30
+
python manage.py migrate
31
+
```
32
+
33
+
### Example Usage
34
+
35
+
-**Primary Key Configuration**: Define primary key type globally in `settings.py` or per model:
36
+
```python
37
+
# In settings.py
38
+
LISAN_PRIMARY_KEY_TYPE= models.UUIDField
39
+
40
+
# Per model configuration
41
+
classMyModel(LisanModelMixin, models.Model):
42
+
lisan_primary_key_type = models.UUIDField
43
+
```
44
+
45
+
-**Translation Serializer**: Access structured translation data in API responses with `TranslationSerializer`:
46
+
```json
47
+
{
48
+
"id": 1,
49
+
"title": "Sample Title",
50
+
"description": "Sample Description",
51
+
"translations": [
52
+
{
53
+
"language_code": "am",
54
+
"title": "ምሳሌ ርእስ",
55
+
"description": "ምሳሌ መግለጫ"
56
+
},
57
+
{
58
+
"language_code": "en",
59
+
"title": "Sample Title",
60
+
"description": "Sample Description"
61
+
}
62
+
]
63
+
}
64
+
```
65
+
66
+
---
67
+
1
68
## [v0.1.4] - 2024-10-07
2
69
3
70
This release introduces improvements in the translation validation process for partial updates, ensuring that translations are properly validated unless explicitly omitted in partial updates.
# Optionally specify UUIDField as primary key for translation tables
104
+
lisan_primary_key_type = models.UUIDField
105
+
89
106
classMeta:
90
107
ordering = ['created']
91
108
```
@@ -162,9 +179,9 @@ To create a snippet with translations, send a `POST` request to the appropriate
162
179
}
163
180
```
164
181
165
-
### 2. Retrieving a Snippet with a Specific Translation
182
+
### 2. Retrieving a Snippet with Translations Using Nested Translation Serializer
166
183
167
-
To retrieve a snippet in a specific language, send a `GET` request with the appropriate `Accept-Language` header to specify the desired language (e.g., `am` for Amharic).
184
+
To retrieve translations for a snippet, use the `TranslationSerializer`to structure the translations in a nested format.
168
185
169
186
**Request Example**:
170
187
@@ -173,15 +190,27 @@ GET /api/snippets/1/
173
190
Accept-Language: am
174
191
```
175
192
176
-
The response will return the snippet information in the requested language if available, or it will fallback to the default language:
193
+
The response will include all translations for the snippet in a structured format:
177
194
178
195
**Response Example**:
179
196
180
197
```json
181
198
{
182
199
"id": 1,
183
-
"title": "ኮድ ቅርጸት ምሳሌ",
184
-
"description": "እንቁ ምሳሌ"
200
+
"title": "Code Snippet Example",
201
+
"description": "Example Description",
202
+
"translations": [
203
+
{
204
+
"language_code": "am",
205
+
"title": "ኮድ ቅርጸት ምሳሌ",
206
+
"description": "እንቁ ምሳሌ"
207
+
},
208
+
{
209
+
"language_code": "en",
210
+
"title": "Code Snippet Example",
211
+
"description": "Example Description"
212
+
}
213
+
]
185
214
}
186
215
```
187
216
@@ -219,7 +248,9 @@ from googletrans import Translator
219
248
from lisan.translation_services import BaseTranslationService
0 commit comments