-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add another test model and set up django-admin
- Loading branch information
1 parent
d11b767
commit 063eb16
Showing
11 changed files
with
752 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib import admin | ||
|
||
from modeltranslation.admin import TranslationAdmin | ||
|
||
from . import models | ||
|
||
|
||
@admin.register(models.ModelWithConstraint) | ||
class UniqueNullableModelAdmin(TranslationAdmin): | ||
pass |
1,007 changes: 649 additions & 358 deletions
1,007
modeltranslation/tests/migrations/0001_initial.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
from modeltranslation.translator import TranslationOptions, translator | ||
from modeltranslation import translator | ||
|
||
from .test_app.models import Other | ||
from .test_app import models | ||
|
||
|
||
class OtherTranslationOptions(TranslationOptions): | ||
@translator.register(models.Other) | ||
class OtherTranslationOptions(translator.TranslationOptions): | ||
fields = ("name",) | ||
|
||
|
||
translator.register(Other, OtherTranslationOptions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.test import Client | ||
from django.urls import reverse | ||
import pytest | ||
from modeltranslation.tests.models import ModelWithConstraint | ||
from django.db import IntegrityError | ||
|
||
|
||
def test_create_duplicate(admin_client: Client): | ||
ModelWithConstraint.objects.create(title="1", sub_title="One") | ||
url = reverse("admin:tests_modelwithconstraint_add") | ||
|
||
with pytest.raises(IntegrityError): | ||
response = admin_client.post( | ||
url, {"title": "1", "sub_title_en": "One", "sub_title_de": "Ein"} | ||
) | ||
|
||
assert response.status_code == 302 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
from modeltranslation.translator import TranslationOptions, translator | ||
from modeltranslation import translator | ||
|
||
from .models import News | ||
from . import models | ||
|
||
|
||
class NewsTranslationOptions(TranslationOptions): | ||
@translator.register(models.News) | ||
class NewsTranslationOptions(translator.TranslationOptions): | ||
fields = ("title",) | ||
|
||
|
||
translator.register(News, NewsTranslationOptions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
urlpatterns = [] | ||
from django.contrib import admin | ||
from django.urls import path | ||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
] |