Django Social Links Field
Overview
social-links-field is a Django package that provides a custom model field, form field, and widget for managing social media links with ease. It allows developers to store and manage multiple social media links for a model with built-in validation and a user-friendly interface.
Features
- Custom JSON-based field for storing social media links
- Predefined social media platforms
- Dynamic form widget for adding/removing social links
- Built-in validation
- Easy integration with Django forms and admin interface
Installation
Install the package using pip:
pip install django-social-links-field
Quick Start
1. Add to INSTALLED_APPS
In your Django project's settings.py:
INSTALLED_APPS = [
...
'social_links_field',
...
]
2. Use in Models
from django.db import models
from social_links_field.models import SocialLinksField
class UserProfile(models.Model):
name = models.CharField(max_length=100)
social_links = SocialLinksField()
3. In Django Admin
The field automatically works with Django admin:
from django.contrib import admin
from .models import UserProfile
@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
# No special configuration needed
pass
Supported Social Media Platforms
- GitHub
- YouTube
- Custom
Configure the dropdown values from settings.py
SOCIAL_LINKS_FIELD_MEDIA_TYPES = [
# value, label
("facebook", "Facebook"),
("instagram", "Instagram"),
("twitter", "Twitter"),
("linkedin", "LinkedIn"),
("github", "GitHub"),
("youtube", "YouTube"),
]
Data Structure
Social links are stored as a list of dictionaries:
[
{
'type': 'facebook',
'link': 'example_user',
'label': 'My Facebook Profile'
}
]
Form Usage
from django import forms
from .models import UserProfile
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ['name', 'social_links']
Customization
Adding Custom Social Media Platforms
You can extend SOCIAL_MEDIA_TYPES in your project:
from social_links_field.models import SOCIAL_MEDIA_TYPES
SOCIAL_MEDIA_TYPES += [
('tiktok', 'TikTok'),
('telegram', 'Telegram')
]
You can customize html/css/js by directly overriding default widget html template
social_links_field/social_links_widget.html
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License
Metadata
Release files for django-social-links-field 0.1.6
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 | Actions |
|---|---|---|---|---|
| django_social_links_field-0.1.6.tar.gz | 68.2 kB | Without provenance | Details for django_social_links_field-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_social_links_field-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for django_social_links_field-0.1.6-py3-none-any.whl |
Total release size: 138.1 kB
Security for django-social-links-field 0.1.6
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.