File: helper.py

package info (click to toggle)
python-django-pint 0.7.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: python: 1,531; makefile: 28; sh: 12
file content (33 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from django.db.models.base import ModelBase

from typing import Dict

from quantityfield.fields import QuantityFieldMixin

from .models import *  # noqa: F401, F403


def get_test_models() -> Dict[str, ModelBase]:
    """
    Get a list of all Test models
    """
    result = {}
    for name, obj in globals().items():
        if not name.startswith("_"):
            if isinstance(obj, ModelBase):
                if not obj._meta.abstract:
                    if obj._meta.app_config.name.endswith("dummyapp"):
                        result[name] = obj
    return result


def print_admins():
    for model in sorted(get_test_models().keys()):
        print(f"admin.site.register({model}, ReadOnlyEditing)")


def print_test_admin_choices():
    for model_name, model in get_test_models().items():
        for field in model._meta.fields:
            if isinstance(field, QuantityFieldMixin):
                print(f"(models.{model_name}, '{field.name}'),")