Current collected state Current
Observed since 20 Oct, 19:41 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Custom Django admin mixin and widgets for handling generic foreign keys (GFKs) more intuitively.
Custom Django admin mixin and widgets for handling generic foreign keys (GFKs) more intuitively.
pip install admin_pretty_gfk
from admin_pretty_gfk.mixins import PrettyGFKModelAdminMixin
from django.contrib import admin
class AdvertAdmin(PrettyGFKModelAdminMixin, admin.ModelAdmin):
pass
from admin_pretty_gfk.widgets import ContentTypeSelect, ForeignKeyContentIdWidget
from django import forms
from django.contrib import admin
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import ManyToOneRel
from common.models import Buy, Sell, Rent, Advert
class AdvertModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AdvertModelForm, self).__init__(*args, **kwargs)
try:
model = self.instance.content_type.model_class()
model_key = model._meta.pk.name
except (AttributeError, ObjectDoesNotExist):
model = self.fields['content_type'].queryset[0].model_class()
model_key = 'id'
self.fields['object_id'].widget = ForeignKeyContentIdWidget(
rel=ManyToOneRel(model_key, model, 'id'),
admin_site=admin.site
)
class Meta:
model = Advert
fields = "__all__"
widgets = {
'content_type': ContentTypeSelect
}
class AdvertAdmin(admin.ModelAdmin):
form = AdvertModelForm
admin.site.register(Buy)
admin.site.register(Sell)
admin.site.register(Rent)
admin.site.register(Advert, AdvertAdmin)
PrettyGFKModelAdminMixin automates form handling for models with GFKs.ContentTypeSelect updates object selection dynamically when the content type changes.ForeignKeyContentIdWidget ensures proper URL handling for related objects.Default create form
Create form with admin_pretty_gfk
Default edit object form
Edit object form with admin_pretty_gfk

This project is licensed under the MIT License.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.0.4 | 5 Feb 2025 | 1 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 19:41 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:6014802941af5ae26d28a7ab7cc98b1c0d5e2bbd652c11307fabd153846a529d