Skip to main content

Choice-composer:

It will help you to make choice filed in Django or anywhere in python script according to your choices :smiley:

Installation

pip install choice-composer

How to use it?

from choice_composer import Choice
# Write a class by extending Choice:
class UserRole(Choice):  
	ADMIN = 1  
	NORMAL_USER = 2  
	CLIENT = 3
# Let's see the how we can use it in django model:
class UserProfile(models.Model):  
	#......
	role = models.PositiveIntegerField(choices=UserRole.choices(), default=UserRole.NORMAL_USER)
	# If you want to get exact name of role then you can use property method by the following way:
	@property
	def user_role(self):
		return UserRole(self.role).name.title() 

*** If you want to filter data by specific role then you can use the following way:

def role_wise_users(role=UserRole.CLIENT):
	# It returns all the client users from UserProfile model.
	users = UserProfile.objects.filter(role=role)
	return users

License

© 2021 Imam Hossain Roni

This repository is licensed under the MIT license. See LICENSE for details.

Metadata

Release files for choice-composer 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for choice-composer 1.0.3
File Size Uploaded
choice-composer-1.0.3.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for choice-composer 1.0.3
File Interpreter ABI Platform
choice_composer-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / choice-composer-1.0.3.tar.gz

Download URL choice-composer-1.0.3.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0d183b0993fd7dfa22702d17f2d2a6622bf5ea10e4eb2f69f8a59b5e5d6d1b04
BLAKE2b-256 checksum
How to use checksums
61f5bb1a7ca1ee0a964f9ffa43357a094fd88103dbe5d46953228597a3ae9d8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.9

Release files / choice_composer-1.0.3-py3-none-any.whl

Download URL choice_composer-1.0.3-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f372e3613a5e51fd8523cb5000d571bcaa5421a7be29de046de9a9d6bd305ed
BLAKE2b-256 checksum
How to use checksums
03c4d6b1693f58d0224785d9ebf20fe6d3acb8fdbf3480e1ef4e106cae2f1383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page