-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use object instance when getting _meta info in admin
Make sure to use the object instance in admin.py in order to get the correct app_label and model_name. This is important when a subclass (e.g. of Newsletter) is used.
- Loading branch information
Showing
2 changed files
with
27 additions
and
2 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
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,25 @@ | ||
from django.test import TestCase | ||
|
||
from newsletter.models import Newsletter | ||
|
||
|
||
class CustomNewsletter(Newsletter): | ||
class Meta: | ||
app_label = 'name_of_my_app' | ||
|
||
|
||
class ModelTestCase(TestCase): | ||
""" Test case for models. """ | ||
|
||
def test_newsletter_label_name(self): | ||
""" Test that _meta returns correct app_label and model_name. """ | ||
self.assertEqual(Newsletter._meta.app_label, 'newsletter') | ||
self.assertEqual(Newsletter._meta.model_name, 'newsletter') | ||
|
||
obj = Newsletter() | ||
self.assertEqual(obj._meta.app_label, 'newsletter') | ||
self.assertEqual(obj._meta.model_name, 'newsletter') | ||
|
||
custom_obj = CustomNewsletter() | ||
self.assertEqual(custom_obj._meta.app_label, 'name_of_my_app') | ||
self.assertEqual(custom_obj._meta.model_name, 'customnewsletter') |