معرفی شرکت ها


django-model-choices-1.0.0


Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر

توضیحات

Django Model Choices provides a neat and DRY way to specify the `choices` option for a Django models and forms.
ویژگی مقدار
سیستم عامل -
نام فایل django-model-choices-1.0.0
نام django-model-choices
نسخه کتابخانه 1.0.0
نگهدارنده []
ایمیل نگهدارنده []
نویسنده Eerik Sven Puudist
ایمیل نویسنده eerik@herbfoods.eu
آدرس صفحه اصلی https://gitlab.com/eeriksp/django-model-choices
آدرس اینترنتی https://pypi.org/project/django-model-choices/
مجوز -
# Django Model Choices Django Model Choices (DMC) provides a readable and DRY way to specify choices for Django models and forms. Although there are many similar projects available, Django Model Choices is willing to offer the most neat and DRY syntax. ## Features A classic choices class in Django looks like this: ```py class CharityType(models.Model): SOCIAL = 'SOC' ENVIRONMENTAL = 'ENV' EDUCATIONAL = 'EDU' CHOICES = ( (SOCIAL, 'Social'), (ENVIRONMENTAL, 'Environmental'), (EDUCATIONAL, 'Educational'), ) ``` This is far from being DRY and is also prone to typos and other mistakes. Using Django Model Choices you could do: ```py from modelchoices import Choices class CharityType(Choices): SOCIAL = ('SOC', 'Social') ENVIRONMENTAL = ('ENV', 'Environmental') EDUCATIONAL = ('EDU', 'Educational') ``` The value of each choice must be a tuple containing a value for the database and a user readable value, which could also be translation object as in this example. The `CHOICES` field will be generated magically by the metaclass, so you can use it in the model like this: ```py class Charity(models.Model): charity_type = models.CharField(max_length=1, choices=CharityType.CHOICES) ``` The variables `SOCIAL`, `ENVIRONMENTAL` and `EDUCATIONAL` can be used to programmatically represent the choice values. Once the class is created, their values are no longer a tuples, but only the database fields (so `CharityType.ENVIRONMENTAL` is equal to `'ENV'`). So you can do: ```py charity = Charity() charity.charity_type = CharityType.ENVIRONMENTAL charity.save() ``` Another field generated magically is `VALUE_MAPPER`. It is a dictionary, where the keys represent the database values and the dictionary values represent the variable name used to declare the options. In our example `VALUE_MAPPER` look like this: ```py >>> CharityType.VALUE_MAPPER { 'SOC': 'SOCIAL', 'ENV': 'ENVIRONMENTAL', 'EDU': 'EDUCATIONAL' } ``` This is useful if you need to use the variable names a codes (for a REST API for instance), because the user readable values might be subjects of translation.


نحوه نصب


نصب پکیج whl django-model-choices-1.0.0:

    pip install django-model-choices-1.0.0.whl


نصب پکیج tar.gz django-model-choices-1.0.0:

    pip install django-model-choices-1.0.0.tar.gz