Django Comma Integer Field
A Django custom field that displays integers with comma separators in the admin interface while providing real-time comma formatting as you type.
Features
- 🔢 Comma-separated display: Shows integers with proper thousand separators (e.g.,
1,234,567) - ⚡ Real-time formatting: Automatically adds commas as you type
- 🎯 Smart input validation: Only allows valid integer input
- 💾 Database efficiency: Stores plain integers in the database
- 🎨 Django admin integration: Works seamlessly with Django admin
- 🔧 Easy to use: Drop-in replacement for Django's IntegerField
- 🌐 Cross-browser compatible: Works in all modern browsers
Installation
Install using pip:
pip install django-comma-integer-field
Add to your Django settings:
INSTALLED_APPS = [
# ... your other apps
'django_comma_integer_field',
# ... rest of your apps
]
Usage
Basic Usage
Replace Django's IntegerField with CommaIntegerField:
from django.db import models
from django_comma_integer_field import CommaIntegerField
class Product(models.Model):
name = models.CharField(max_length=100)
price = CommaIntegerField(default=0, help_text="Price in cents")
stock_quantity = CommaIntegerField(null=True, blank=True)
class Demographics(models.Model):
city = models.CharField(max_length=100)
population = CommaIntegerField(help_text="Total population")
Admin Integration
The field automatically works with Django admin:
from django.contrib import admin
from .models import Product
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ['name', 'price', 'stock_quantity']
# CommaIntegerField will automatically display with commas
Advanced Usage
You can use all the same options as Django's IntegerField:
class Statistics(models.Model):
# With validation
revenue = CommaIntegerField(
help_text="Annual revenue in USD",
validators=[MinValueValidator(0)]
)
# With choices
PRIORITY_CHOICES = [
(1, 'Low'),
(100, 'Medium'),
(1000, 'High'),
]
priority_score = CommaIntegerField(
choices=PRIORITY_CHOICES,
default=1
)
# Nullable field
optional_metric = CommaIntegerField(
null=True,
blank=True,
help_text="Optional statistical data"
)
How It Works
Display Format
- Database: Stores as regular integer (e.g.,
1234567) - Admin Interface: Displays with commas (e.g.,
1,234,567) - Form Input: Accepts input with or without commas
- Real-time: Adds commas automatically as you type
Technical Details
- Widget: Uses a custom
CommaIntegerWidgetthat renders as a text input - JavaScript: Provides real-time formatting with intelligent cursor positioning
- Validation: Ensures only valid integers are accepted
- Storage: Removes commas before saving to database
Browser Support
- ✅ Chrome (all versions)
- ✅ Firefox (all versions)
- ✅ Safari (all versions)
- ✅ Edge (all versions)
- ✅ Internet Explorer 11+
Examples
Real-time Formatting Demo
When you type in the admin interface:
- Type:
1234567→ Displays:1,234,567 - Type:
999999999→ Displays:999,999,999 - Type:
-50000→ Displays:-50,000
Form Integration
from django import forms
from django_comma_integer_field import CommaIntegerFormField
class BudgetForm(forms.Form):
annual_budget = CommaIntegerFormField(
label="Annual Budget",
help_text="Enter the budget amount"
)
Migration from IntegerField
To migrate existing IntegerField to CommaIntegerField:
- Update your model:
# Before
quantity = models.IntegerField()
# After
quantity = CommaIntegerField()
- Create and run migration:
python manage.py makemigrations
python manage.py migrate
No data migration needed - the database column type remains the same!
Customization
Custom Widget Attributes
from django_comma_integer_field import CommaIntegerWidget
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
CommaIntegerField: {
'widget': CommaIntegerWidget(attrs={
'style': 'width: 200px;',
'placeholder': 'Enter amount...'
})
},
}
Custom CSS Classes
The widget automatically adds the comma-integer-field CSS class for styling:
.comma-integer-field {
text-align: right;
font-family: monospace;
background-color: #f8f9fa;
}
Requirements
- Django 3.2+
- Python 3.8+
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
Made with ❤️ for the Django community
Metadata
Release files for django-comma-integer-field 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_comma_integer_field-1.0.0.tar.gz | 10.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_comma_integer_field-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.1 kB
Release files / django_comma_integer_field-1.0.0.tar.gz
| Download URL | django_comma_integer_field-1.0.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ab11d119759d9c9e53ad1c469b80a2f99ecc0a973d48fe51c7a1023e1f99e14
|
|
BLAKE2b-256 checksum How to use checksums |
41367e64312959b5068570dc37a208b56b7f4ea810861aa816825ddd1db29c71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / django_comma_integer_field-1.0.0-py3-none-any.whl
| Download URL | django_comma_integer_field-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd5bba79882380b66c55684eeed0d886c3cbcd8981ac87c1251b219ca526534d
|
|
BLAKE2b-256 checksum How to use checksums |
903fe7215df9d592879623b38774e45901604bc3f04f5ca304584985fd99d920
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for django-comma-integer-field 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.